TheZman Posted October 12, 2010 Share Posted October 12, 2010 It seems so simple right? but I can't figure it out! There is just one specific layer I want to be able to turn on and off with a lisp routine. Quote Link to comment Share on other sites More sharing options...
Grant Posted October 12, 2010 Share Posted October 12, 2010 There are several methods to do this, here is one Make a layer even if it already exists - this will become the current layer (command "layer" "m" "mylayer" "C" "150" "" "L" "Continuous" "" "") now turn off all other layers but keep the current layer on: (COMMAND "LAYER" "OFF" "*" "N" "") Hope this helps Quote Link to comment Share on other sites More sharing options...
alanjt Posted October 13, 2010 Share Posted October 13, 2010 (defun foo (layer / data) (if (and (setq data (tblobjname "LAYER" layer)) (setq data (entget data))) (entmod (subst (cons 62 (- (cdr (assoc 62 data)))) (assoc 62 data) data)) ) ) eg. (foo (getvar 'clayer)) Quote Link to comment Share on other sites More sharing options...
pBe Posted October 13, 2010 Share Posted October 13, 2010 (edited) you can do it this way too.. (defun c:sa () (vl-load-com) (if (= "your_layer" (getvar "clayer")) (princ (strcat "\nYour_layer" " is the current layer")) (progn (if (= ur_flag nil) (progn (setq ur_flag 'T) (vl-cmdf "_.layer" "on" "your_layer" "") ) (progn (vl-cmdf "_.layer" "off" "your_layer" "") (setq ur_flag 'nil) ) ) ) ) (princ) ) since you only have one specific layer to swtich on and off Edited October 13, 2010 by pBe fat fingers syndrome Quote Link to comment Share on other sites More sharing options...
alanjt Posted October 13, 2010 Share Posted October 13, 2010 you can do it this way too.. (defun c:sa () (vl-load-com) (if (= "your_layer" (getvar "clayer")) (princ (strcat "\nYour_layer" " is the current layer")) (progn (if (= ur_flag nil) (progn (setq ur_flag 'T) (vl-cmdf "_.layer" "on" "your_layer" "") ) (progn (vl-cmdf "_.layer" "off" "your_layer" "") (setq ur_flag 'nil) ) ) ) ) (princ) ) since you only have one specific layer to swtich on and off All that does is turn the layer on/off based on the the variable ur_flag being T. Why not check the definition of the layer and just see if it's on or off? Quote Link to comment Share on other sites More sharing options...
pBe Posted October 13, 2010 Share Posted October 13, 2010 thats exactly the point.. yup variable Ur-flag T or nil if the layer is on it will turn it off and vice versa assuming the layer is already existing ... well its the first thing pops into my head .. Quote Link to comment Share on other sites More sharing options...
alanjt Posted October 13, 2010 Share Posted October 13, 2010 thats exactly the point.. yup variable Ur-flag T or nil if the layer is on it will turn it off and vice versa assuming the layer is already existing ... well its the first thing pops into my head .. And if the user wants to toggle the layer off the first time, they will have to issue your command twice, or someone changed the on/off state of the layer after issuing your routine, it will never give the desired toggle result.Like I said, why not base the toggle on actual layer properties, rather than a user set variable? Quote Link to comment Share on other sites More sharing options...
pBe Posted October 13, 2010 Share Posted October 13, 2010 i know what you mean... its just a simple lisp that assumesa particular condition i.e. the layer is already there and the layer is currently turned "off" and you're right about invoking the command twice if you started when the layer is "on" goodcatch alanjt.... what about reversing the sequence... better yet make the first line "off" ? still the same result though... what am i thinking ayt... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 13, 2010 Share Posted October 13, 2010 Another, using VL: (defun LayTog ( layer ) (vl-load-com) (if (not (vl-catch-all-error-p (setq layer (vl-catch-all-apply 'vla-item (list (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)) ) layer ) ) ) ) ) (vlax-put layer 'layeron (~ (vlax-get layer 'layeron))) ) ) Quote Link to comment Share on other sites More sharing options...
pBe Posted October 13, 2010 Share Posted October 13, 2010 There you go... Exactly what Alanjit's pointing out all along... First: Grab the layerstate, then from there it switches from on to off Awesome...... Lee Mac / Alanjit You guys are the best!! I would have written the code that way if given the time.. say like a month!!! Quote Link to comment Share on other sites More sharing options...
David Bethel Posted October 13, 2010 Share Posted October 13, 2010 [b][color=BLACK]([/color][/b]defun toglay [b][color=FUCHSIA]([/color][/b]l[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]"_.LAYER"[/color] [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]minusp [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 62 [b][color=RED]([/color][/b]tblsearch [color=#2f4f4f]"LAYER"[/color] l[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [color=#2f4f4f]"_ON"[/color] [color=#2f4f4f]"_OFF"[/color][b][color=NAVY])[/color][/b] l [color=#2f4f4f]""[/color][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] usage: (toglay "3D") Depending on the release your are using, turning off the current layer can lead to a extra input. QAFLAGS or NOMUTT may be able to compensate for that. Also testing for the existence of the layer wouldn't be a bad thing. -David Quote Link to comment Share on other sites More sharing options...
TheZman Posted October 13, 2010 Author Share Posted October 13, 2010 Thanks everyone. I have A LOT more to learn. Do these forums have +rep because you all deserve some. Quote Link to comment Share on other sites More sharing options...
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.