wkplan Posted February 8, 2010 Posted February 8, 2010 Hi all, with the following code I can create and save a new layer-status: (setq layname (strcat "LAYER_" (menucmd "M=$(edtime,$(getvar,date),MO-DD-YYYY)") ) ) ; create a name for the layerstatus (command "._-layer" "status" "_save" layname "" "" "") ; save current layerstatus Is there a method to check if the layer-status allready exists? Thought about something like TBLSEARCH, but found nothing in the help-files... regards to all Wolfgang Quote
lpseifert Posted February 8, 2010 Posted February 8, 2010 Not sure what you're after, there is no Status option in the -layer command... if you're looking to see if a Layer State exists, look into the (layerstate-getnames) function Quote
StevJ Posted February 8, 2010 Posted February 8, 2010 I use this: (if (tblsearch "LAYER" "NOPLOT") (command "_.Layer" "_S" "NOPLOT" "U" "NOPLOT" "") (Progn (command "_.Layer" "_M" "NOPLOT" "_C" "MAGENTA" "NOPLOT" "_LT" "CONTINUOUS" "NOPLOT" "U" "NOPLOT" "") ) ) It's not pretty, but it works. Steve . Quote
Lee Mac Posted February 8, 2010 Posted February 8, 2010 I think he was looking for layer-states, not the actual layer, but you could tidy your code to this if you like: (if (tblsearch "LAYER" "NOPLOT") (setvar "CLAYER" "NOPLOT") (command "_.-Layer" "_M" "NOPLOT" "_C" "MAGENTA" "NOPLOT" "_LT" "CONTINUOUS" "NOPLOT" "U" "NOPLOT" "")) No need for the second progn Quote
StevJ Posted February 8, 2010 Posted February 8, 2010 OOPS. I misunderstood. Thanks for the cleanup, Lee. (^_^) Steve Quote
wkplan Posted February 8, 2010 Author Posted February 8, 2010 I think he was looking for layer-states, not the actual layer, but you could tidy your code to this if you like: Yes, i meant layer-states. Sorry, but I'm no native speaker, in german this is called "layer-status". Thanks to LeeMac and StevJ, what I simply want is to look, wether a certain layer-state -with a well-known name- exists or not. Please give me some time to look at what lpseifert suggested, the (layerstate-getnames) sounds great. Coming back with the solution (hopefully not with another question!) Wolfgang Quote
Lee Mac Posted February 8, 2010 Posted February 8, 2010 I would use something like: (if (vl-position (strcase <item>) (mapcar (function strcase) (layerstate-getnames))) .. Quote
lpseifert Posted February 8, 2010 Posted February 8, 2010 Hmmm... using 2009 at work, (layerstate-getnames) works. At home using 2008, it doesn't.; doesn't even show up in Developer's Help. Was this function been added in 2009? Quote
wkplan Posted February 14, 2010 Author Posted February 14, 2010 Hi all, and thanks for your answers. I found some entrys for "layerstate" in the 2005-dev-help, but this seems VBA to me... ...still learning lisp, not enough brain to learn another language:lol: As a workaround, I decided to save a current layer-state, and than create a new layer with the same name. By this, I can do a tblsearch for that layer, and if tblsearch fails on looking for that layer, I know that the layer-state hasn't saved yet. I need this functionality, because I wrote a little tool which freezes an object-layer by simply klicking on it. Quite usefull if a drawing has many layers and all are turned on. Thaught it would be pretty nice to save the current layer-state one time before the tool is used. Here is the code: (defun c:freezelayer (/ ent layname freezelayer) ; freezes a layer by clicking an object ; 2010 wkplan (setq OLDCMDECHO (getvar "CMDECHO")) (setq OLDCLAYER (getvar "CLAYER")) ;save vars (setvar "CMDECHO" 0) ;turn cmd-echo off (command "_undo" _begin) ;set a undo-mark (setq freezelayer nil) ;clear variables (setq layname nil) ;now make the old layerstate safe (setq layname (strcat "LAYER_" (menucmd "M=$(edtime,$(getvar,date),MO-DD-YYYY)") ;create a layer-name, including the date ) ) ; create a name for the layerstatus (if (not (tblsearch "LAYER" layname)) ; check if layer "layname" already exists, this indicates wether to save or not a alyer-state (progn ; if layer not exists, than: (command "._-layer" "_state" "_save" layname "" "" "") ;save the current layer-state (command "._-layer" "_make" layname "") ;and create a layer with this name, this layer will be set to the actual working layer (setvar "CLAYER" OLDCLAYER) ;switch back to the previous working layer ) ; end progn ) ; end if (while ; do as long as something is selected (setq ent (car (nentsel "\nChoose object to freeze this layer: " ) ) ) ; select an entity, use the nentsel-method (setq freezelayer (cdr (assoc 8 (entget ent))) ; extract the layername of this entity ) (command "._-layer" "_freeze" freezelayer "") ; freeze that layer ) (command "_undo" _end) ; set a undo-mark (setvar "CMDECHO" OLDCMDECHO) ;restore old cmdecho (princ) ; force a clean exit ) (c:freezelayer) ; make this lisp autostart on loading (princ) I know that this is far away from beeing a perfect code, but maybee it is usefull for other people. regards Wolfgang Quote
Lee Mac Posted February 14, 2010 Posted February 14, 2010 Did my code suggestion in #7 not work for you Wolfgang? Quote
Lee Mac Posted February 14, 2010 Posted February 14, 2010 Wolfgang, If you purely want to freeze the layer by selecting an object, here are two ways you can do it: (defun c:layfrze (/ ent eLst) (if (setq ent (car (nentsel "\nSelect Object to Freeze Layer: "))) (progn (setq eLst (entget (tblobjname "LAYER" (cdr (assoc 8 (entget ent)))))) (entmod (subst (cons 70 (logior 1 (cdr (assoc 70 eLst)))) (assoc 70 eLst) eLst)))) (princ)) (defun c:layfrze (/ ent) (vl-load-com) (if (setq ent (car (nentsel "\nSelect Object to Freeze Layer: "))) (vla-put-freeze (vlax-ename->vla-object (tblobjname "LAYER" (cdr (assoc 8 (entget ent))))) :vlax-true)) (princ)) Obviously checking could also be made to account for if the selected layer is the current layer - but this gives you the idea. Also, bear in mind there is the existing 'layfrz' command. Lee Quote
wkplan Posted February 14, 2010 Author Posted February 14, 2010 Also, bear in mind there is the existing 'layfrz' command. Lee Oops, I didn't think about the express-tools... Lee thank you for your time! Your suggestion in #7 does't work for me, as Ipseifert noticed, layerstate-getnames is not available to versions prior acad2009. The two ways you showed me are a little more elegant than my command-method, maybee I had found the vla-put-freeze-part, but for shure I would never had thought changing the layer-group-code #70! (Looks strange, using entmod to freeze a layer) To me there is no need to check if the selected object is on the current layer: this will only leed to a simple console-message, but the programm stays still in the loop. Anyway, I took this as a learning-lesson, not as wasted time. regards Wolfgang Quote
Lee Mac Posted February 14, 2010 Posted February 14, 2010 You're welcome Wolfgang Most things can be modified using either DXF data, or through Visual LISP - layers, views, plotstyles all have their respective DXF data, as well as equivalent Visual LISP properties & methods. In the case of the layer - the group 70 DXF code is bit-coded, hence we must use such functions as logior and logand to modify its value. As a better example, here is a good piece of work to study, by Stig Madsen: ;; bitcodes: * ;; 0 = nothing * ;; 1 = layer off * ;; 2 = layer freeze * ;; 4 = layer on * ;; 8 = layer thaw * ;; 16 = plot on * ;; 32 = plot off * ;; 64 = current (defun setLayerStatus (cLayer status / blist lBits lCol lEnt lEntl lPlot tmp findBits substitute) (defun findBits (num / a bitList) (setq a 1) (while (>= num a) (and (= (logand num a) a) (setq bitList (cons a bitList))) (setq a (lsh a 1)) ) (reverse bitList) ) (defun substitute (elist code value) (subst (cons code value) (assoc code elist) elist) ) (cond ((and (= (type cLayer) 'STR) (setq lEnt (tblobjname "LAYER" cLayer)) ) (setq lEntl (entget lEnt) lBits (cdr (assoc 70 lEntl)) lCol (cdr (assoc 62 lEntl)) lPlot (cdr (assoc 290 lEntl)) blist '((1 62 (- lCol)) (2 70 (logior lBits 1)) (4 62 (abs lCol)) (8 70 (boole 2 lBits 1)) (16 290 1) (32 290 0) ) ) (foreach bit (findbits status) (and (setq tmp (cdr (assoc bit blist))) (setq lEntl (substitute lEntl (car tmp) (eval (cadr tmp)))) ) ) (and (= 64 (logand status 64)) (setvar "CLAYER" cLayer)) ) ) (entmod lEntl) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.