vernonlee Posted November 8, 2014 Posted November 8, 2014 (edited) Can a kind soul come up with a macro script that can isolate a set of predefined layers base on their names. Thanks Edited November 18, 2014 by vernonlee Quote
BIGAL Posted November 14, 2014 Posted November 14, 2014 -la s 1stlayername off * on layer2 on layer3 etc Quote
vernonlee Posted November 14, 2014 Author Posted November 14, 2014 -la s 1stlayername off * on layer2 on layer3 etc Thanks. Tried it. ^C^C-la s layer1 off* I got this: Command: -la -LAYER Current layer: "layer1" Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: s Enter layer name to make current or : layer1 Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: off* Also I have many layers. Is it possible to key only the layers that need to on without keying in the rest that needs to off? Quote
vernonlee Posted November 15, 2014 Author Posted November 15, 2014 Can someone come up with a lisp that can isolate a set of predefined layers base on their layer names (by adding it to the lisp). Thanks Quote
BIGAL Posted November 15, 2014 Posted November 15, 2014 Off space * then ON do a layer list can be part* or part*,bolt*,nut* or part,nut,bolt or just repeat the ON bolt ON part on nut Just watch the command line for the correct prompts. Quote
Tharwat Posted November 17, 2014 Posted November 17, 2014 You include my function _isolate into your lisp routine to isolate a list of layer names as shown below . (defun _isolate (layers / l c n e) ;; Tharwat 17.Nov.2014 ;; ;; -------------------------- ;; ;; Isolate a specifc list of ;; ;; Layer names . ;; (while (setq l (tblnext "LAYER" (not l))) (setq c (cdr (assoc 62 (setq e (entget (tblobjname "LAYER" (setq n (cdr (assoc 2 l))))) ) ) ) ) (if (member n layers) (if (minusp c) (entmod (subst (cons 62 (abs c)) (assoc 62 e) e)) ) (if (not (minusp c)) (entmod (subst (cons 62 (- c)) (assoc 62 e) e)) ) ) ) (princ) ) Usage of the function : (_isolate '("Layer1" "Layer2" "Layer3")) Quote
vernonlee Posted November 17, 2014 Author Posted November 17, 2014 Off space * then ON do a layer list can be part* or part*,bolt*,nut* or part,nut,bolt or just repeat the ON bolt ON part on nut Just watch the command line for the correct prompts. Hi bro. I did not get it at first but tried it & it worked. It is a nice workaround, but it will only work if i can get back to the previous layering setting. Any idea on that? Thanks Quote
vernonlee Posted November 17, 2014 Author Posted November 17, 2014 You include my function _isolate into your lisp routine to isolate a list of layer names as shown below . (defun _isolate (layers / l c n e) ;; Tharwat 17.Nov.2014 ;; ;; -------------------------- ;; ;; Isolate a specifc list of ;; ;; Layer names . ;; (while (setq l (tblnext "LAYER" (not l))) (setq c (cdr (assoc 62 (setq e (entget (tblobjname "LAYER" (setq n (cdr (assoc 2 l))))) ) ) ) ) (if (member n layers) (if (minusp c) (entmod (subst (cons 62 (abs c)) (assoc 62 e) e)) ) (if (not (minusp c)) (entmod (subst (cons 62 (- c)) (assoc 62 e) e)) ) ) ) (princ) ) Usage of the function : (_isolate '("Layer1" "Layer2" "Layer3")) Hi Tharwat. I do not have a lisp routine to isolate. Can clarify? Thanks Quote
Tharwat Posted November 17, 2014 Posted November 17, 2014 (edited) I do not have a lisp routine to isolate. Can clarify? But you have mentioned in your first post that you want the codes to add them to a lisp ? Can someone come up with a lisp that can isolate a set of predefined layers base on their layer names (by adding it to the lisp). What clarification you are asking for ? Edited November 17, 2014 by Tharwat typo Quote
vernonlee Posted November 17, 2014 Author Posted November 17, 2014 But you have mentioned in your first post that you want the codes to add them to a lisp ? What clarification you are asking for ? If you are refering to the "........(by adding to the lisp)" in my 1st post, i was actually referring to looking for a standalone lisp, where i can key into that lisp; predefined layer names to isolate those layers when i run that lisp. I hope that is clearer. Quote
Tharwat Posted November 17, 2014 Posted November 17, 2014 Have a look . (defun c:Test ( / lays l c n e) ;; Tharwat 17.Nov.2014 ;; ;; -------------------------- ;; ;; Isolate a specifc list of ;; ;; Layer names . ;; [color=red] (setq lays '("Layer1" "Layer2" "Layer3")) ;; < Change this list of layer names to meet your needs .[/color] (while (setq l (tblnext "LAYER" (not l))) (setq c (cdr (assoc 62 (setq e (entget (tblobjname "LAYER" (setq n (cdr (assoc 2 l))))) ) ) ) ) (if (member n lays) (if (minusp c) (entmod (subst (cons 62 (abs c)) (assoc 62 e) e)) ) (if (not (minusp c)) (entmod (subst (cons 62 (- c)) (assoc 62 e) e)) ) ) ) (princ) ) Quote
vernonlee Posted November 17, 2014 Author Posted November 17, 2014 Have a look . (defun c:Test ( / lays l c n e) ;; Tharwat 17.Nov.2014 ;; ;; -------------------------- ;; ;; Isolate a specifc list of ;; ;; Layer names . ;; [color=red] (setq lays '("Layer1" "Layer2" "Layer3")) ;; < Change this list of layer names to meet your needs .[/color] (while (setq l (tblnext "LAYER" (not l))) (setq c (cdr (assoc 62 (setq e (entget (tblobjname "LAYER" (setq n (cdr (assoc 2 l))))) ) ) ) ) (if (member n lays) (if (minusp c) (entmod (subst (cons 62 (abs c)) (assoc 62 e) e)) ) (if (not (minusp c)) (entmod (subst (cons 62 (- c)) (assoc 62 e) e)) ) ) ) (princ) ) It worked. it did isolate the required layer. But the unisolate command would not get back the original layering setting before it "isolate"? Can it be included into the lisp you have written? Apologies for not being clearer. Basically i needed to isolate a predefine layers, after i have amended the drawings, I would like for them to go back to what it was before the drawings was "isolated" I did not mention eariler as i though the unisolate command will work. Thanks Quote
YZ Posted November 17, 2014 Posted November 17, 2014 There is a command called LAYERP It restores the previous layer settings. I always return to all layers on, but if you have more complicated settings and want to return to some being on and some being off then try LAYERP. Setting the variable "Expert" to 3 at start of your macro will prevent AutoCAD from asking you if you are sure you want to turn off current layer. Quote
Tharwat Posted November 18, 2014 Posted November 18, 2014 It worked. it did isolate the required layer. But the unisolate command would not get back the original layering setting before it "isolate"? Can it be included into the lisp you have written? Apologies for not being clearer. Basically i needed to isolate a predefine layers, after i have amended the drawings, I would like for them to go back to what it was before the drawings was "isolated" I did not mention eariler as i though the unisolate command will work. Thanks You may look for something like this ? NOTE: Don't forget to change the list of layer names as per yours . (defun c:[color=red]Test-1[/color] (/ l n lst) (setq *Lays_Status1* nil *Lays_Status2* nil l '([color=magenta]"Layer1" "Layer3" "Layer5"[/color]) ) (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)) ) (if (member (setq n (vla-get-name x)) l) (progn (setq *Lays_Status1* (cons (list n (vla-get-layeron x)) *Lays_Status1* ) ) (vla-put-layeron x :vlax-true) ) (progn (setq *Lays_Status2* (cons (list n (vla-get-layeron x)) *Lays_Status2* ) ) (vla-put-layeron x :vlax-false) ) ) ) (princ) ) ;; ;; (defun c:[color=blue]Test-2[/color] (/ l n as) (setq l '([color=magenta]"Layer1" "Layer3" "Layer5"[/color])) (if (and *Lays_Status1* *Lays_Status2*) (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)) ) (cond ((setq as (assoc (setq n (vla-get-name x)) *Lays_Status1*)) (vla-put-layeron x (cadr as)) ) ((setq as (assoc (setq n (vla-get-name x)) *Lays_Status2*)) (vla-put-layeron x (cadr as)) ) ) ) ) (setq *Lays_Status1* nil *Lays_Status2* nil ) (princ) )(vl-load-com) Quote
vernonlee Posted November 18, 2014 Author Posted November 18, 2014 There is a command called LAYERP It restores the previous layer settings. I always return to all layers on, but if you have more complicated settings and want to return to some being on and some being off then try LAYERP. Setting the variable "Expert" to 3 at start of your macro will prevent AutoCAD from asking you if you are sure you want to turn off current layer. Cool. That more or less solve my issue. I will make another macro for the LAYERP & i should be good to go. Hurray!! btw i check my expert setting , & it was 0. But it still off it without asking me. Thanks bro. Quote
Lee Mac Posted November 18, 2014 Posted November 18, 2014 It worked. it did isolate the required layer. But the unisolate command would not get back the original layering setting before it "isolate"? Assuming you are using a version of AutoCAD in which the LAYISO command is available as standard, try the following: (defun c:mylayiso ( / lay sel ) (setq lay "layer1,layer2,layer3") (if (setq sel (ssget "_X" (list (cons 8 lay) (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))) (command "_.layiso" sel "") ) (princ) ) You can then use the LAYUNISO command to unisolate the layers. 1 Quote
vernonlee Posted November 19, 2014 Author Posted November 19, 2014 You may look for something like this ? NOTE: Don't forget to change the list of layer names as per yours . (defun c:[color=red]Test-1[/color] (/ l n lst) (setq *Lays_Status1* nil *Lays_Status2* nil l '([color=magenta]"Layer1" "Layer3" "Layer5"[/color]) ) (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)) ) (if (member (setq n (vla-get-name x)) l) (progn (setq *Lays_Status1* (cons (list n (vla-get-layeron x)) *Lays_Status1* ) ) (vla-put-layeron x :vlax-true) ) (progn (setq *Lays_Status2* (cons (list n (vla-get-layeron x)) *Lays_Status2* ) ) (vla-put-layeron x :vlax-false) ) ) ) (princ) ) ;; ;; (defun c:[color=blue]Test-2[/color] (/ l n as) (setq l '([color=magenta]"Layer1" "Layer3" "Layer5"[/color])) (if (and *Lays_Status1* *Lays_Status2*) (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)) ) (cond ((setq as (assoc (setq n (vla-get-name x)) *Lays_Status1*)) (vla-put-layeron x (cadr as)) ) ((setq as (assoc (setq n (vla-get-name x)) *Lays_Status2*)) (vla-put-layeron x (cadr as)) ) ) ) ) (setq *Lays_Status1* nil *Lays_Status2* nil ) (princ) )(vl-load-com) Thanks Tharwat. It worked. This is gonna be very useful. Assuming you are using a version of AutoCAD in which the LAYISO command is available as standard, try the following: (defun c:mylayiso ( / lay sel ) (setq lay "layer1,layer2,layer3") (if (setq sel (ssget "_X" (list (cons 8 lay) (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))) (command "_.layiso" sel "") ) (princ) ) You can then use the LAYUNISO command to unisolate the layers. Thanks Lee Mac. It works too. I do like yours as well & if you can have it work in paperspace (layout tab) that would be even better. Quote
Tharwat Posted November 19, 2014 Posted November 19, 2014 Thanks Tharwat. It worked. This is gonna be very useful. Good for you - you are welcome. Quote
vernonlee Posted November 25, 2014 Author Posted November 25, 2014 I like to re-open this thread again as I frequently found out that instead of a fixed layer name, i have encounter layers that share the same name but with a slight difference. So is it possible to incoporate a wildcard name eg. *rev* Thanks 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.