lpetrovi Posted May 22, 2013 Posted May 22, 2013 (edited) Is there a way to incorporate the "-layer" command into a lisp routine to accomplish the task of turning off all layers except a certain 5 that will always be the same layers that I want to keep on? I am currently using this to turn off all layers except the current one but do not know how to modify the code to keep the same 5 layers on all the time.. (defun C:loff ( / clayer expert) (setq clayer (getvar "clayer") expert (getvar "expert")) (setvar "expert" 1) (command "._layer" "_off" "*" "_on" clayer "") (setvar "expert" expert) (princ) ) Edited May 23, 2013 by SLW210 Code tags added! Quote
lpetrovi Posted May 22, 2013 Author Posted May 22, 2013 (edited) Is there a way to incorporate the "-layer" command into a lisp routine to accomplish the task of turning off all layers except a certain 5 that will always be the same layers that I want to keep on? For example, I would like to turn off all layers except the following: Storm_Drains Building HVAC Sprinkler Parking_Lot I am currently using this LISP to turn off all layers except the current one but do not know how to modify the code to keep those same 5 layers on all the time.. (defun C:loff ( / clayer expert) (setq clayer (getvar "clayer") expert (getvar "expert")) (setvar "expert" 1) (command "._layer" "_off" "*" "_on" clayer "") (setvar "expert" expert) (princ) ) Edited May 23, 2013 by SLW210 Added Code Tags! Quote
alanjt Posted May 22, 2013 Posted May 22, 2013 Is there a way to incorporate the "-layer" command into a lisp routine to accomplish the task of turning off all layers except a certain 5 that will always be the same layers that I want to keep on? I am currently using this to turn off all layers except the current one but do not know how to modify the code to keep the same 5 layers on all the time.. (defun C:loff ( / clayer expert) (setq clayer (getvar "clayer") expert (getvar "expert")) (setvar "expert" 1) (command "._layer" "_off" "*" "_on" clayer "") (setvar "expert" expert) (princ) ) Where it says clayer, you can add change it to "LAYER1,LAYER2,LAYER3,LAYER4,LAYER5". LAYER# being the name of each layer you want to be left on. Quote
SLW210 Posted May 22, 2013 Posted May 22, 2013 I moved your thread to the AutoLISP, Visual LISP & DCL forum. Please read the Code posting guidelines and place your code in code tags. Quote
SLW210 Posted May 22, 2013 Posted May 22, 2013 I added the posts from the other thread to this one. Quote
lpetrovi Posted May 22, 2013 Author Posted May 22, 2013 Where it says clayer, you can add change it to "LAYER1,LAYER2,LAYER3,LAYER4,LAYER5". LAYER# being the name of each layer you want to be left on. Thank you again for your help on that one! Is there a limit to the number of layers that I can have it turn on? Because when I go to leave 160 layers on I keep getting the following error in the command line: ; error: bad argument value: AutoCAD command: #<SUBR @000000002cafd6b0 COND> Quote
Lee Mac Posted May 22, 2013 Posted May 22, 2013 Although the error message you have received seems odd given the circumstances, there may well be a limit to the length of a string which may be passed to a command. Try this instead: (defun c:loff ( / l ) (setq l (mapcar 'strcase '( [color=green];; Layers to keep ON:[/color] [highlight]"LAYER1"[/highlight] [highlight]"LAYER2"[/highlight] [highlight]"LAYER3"[/highlight] ) ) ) (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (member (strcase (vla-get-name x)) l) (vla-put-layeron x :vlax-true) (vla-put-layeron x :vlax-false) ) ) (princ) ) (vl-load-com) (princ) Change the layers in the highlighted list as required. Quote
alanjt Posted May 23, 2013 Posted May 23, 2013 Although the error message you have received seems odd given the circumstances, there may well be a limit to the length of a string which may be passed to a command. Try this instead: (defun c:loff ( / l ) (setq l (mapcar 'strcase '( [color=green];; Layers to keep ON:[/color] [highlight]"LAYER1"[/highlight] [highlight]"LAYER2"[/highlight] [highlight]"LAYER3"[/highlight] ) ) ) (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (member (strcase (vla-get-name x)) l) (vla-put-layeron x :vlax-true) (vla-put-layeron x :vlax-false) ) ) (princ) ) (vl-load-com) (princ) Change the layers in the highlighted list as required. Another advantage to Lee's code is that it can be executed transparently, and will run a lot faster than using COMMAND. I've never noticed limitations when feeding a string to the LAYER command, but I must admit, I've never fed it more than wildcards when writing quick macros. If if was any thing like the scale you are wanting, I'd definitely write it without the use of COMMAND. Quote
Tharwat Posted May 23, 2013 Posted May 23, 2013 (edited) If any of your layers is not existed in the drawing , all layers would be off . (defun c:Test (/ l e c) ;;;--- Tharwat 23. May. 2013 ---;;; (while (setq l (tblnext "LAYER" (not l))) (setq c (assoc 62 (setq e (entget (tblobjname "LAYER" (cdr (assoc 2 l))))) ) ) (if (member (strcase (cdr (assoc 2 l))) (mapcar 'strcase '("Storm_Drains" "Building" "HVAC" "Sprinkler" "Parking_Lot" ) ) ) (if (minusp (cdr c)) (entmod (subst (cons 62 (- (cdr c))) c e)) ) (if (not (minusp (cdr c))) (entmod (subst (cons 62 (- (cdr c))) c e)) ) ) ) (princ) ) Edited May 23, 2013 by Tharwat Quote
Lee Mac Posted May 23, 2013 Posted May 23, 2013 If any of your layers is not existed in the drawing , all layers would be off Try running it twice. Quote
Tharwat Posted May 23, 2013 Posted May 23, 2013 Try running it twice. Thank you . I didn't expect that , codes modified . Quote
Lee Mac Posted May 23, 2013 Posted May 23, 2013 I didn't expect that , codes modified . What if one of the layers to remain on is already turned off? Quote
Tharwat Posted May 23, 2013 Posted May 23, 2013 What if one of the layers to remain on is already turned off? Also modified . Quote
Lee Mac Posted May 23, 2013 Posted May 23, 2013 For what its worth, if a Vanilla AutoLISP solution is required, here is how I might approach it: ([color=BLUE]defun[/color] c:loff ( [color=BLUE]/[/color] c l n x ) ([color=BLUE]setq[/color] l ([color=BLUE]mapcar[/color] '[color=BLUE]strcase[/color] '( [color=GREEN];; Layers to keep ON:[/color] [color=MAROON]"LAYER1"[/color] [color=MAROON]"LAYER2"[/color] [color=MAROON]"LAYER3"[/color] ) ) ) ([color=BLUE]while[/color] ([color=BLUE]setq[/color] x ([color=BLUE]tblnext[/color] [color=MAROON]"layer"[/color] ([color=BLUE]null[/color] x))) ([color=BLUE]setq[/color] n ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 02 x)) c ([color=BLUE]abs[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 62 x))) ) ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]member[/color] ([color=BLUE]strcase[/color] n) l)) ([color=BLUE]setq[/color] c ([color=BLUE]-[/color] c)) ) ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] 62 c) ([color=BLUE]assoc[/color] 62 x) ([color=BLUE]entget[/color] ([color=BLUE]tblobjname[/color] [color=MAROON]"layer"[/color] n)))) ) ([color=BLUE]princ[/color]) ) Quote
Tharwat Posted May 23, 2013 Posted May 23, 2013 For what its worth, if a Vanilla AutoLISP solution is required, here is how I might approach it: I have to admit that your work is very neat indeed . 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.