takeanosan Posted July 22, 2014 Share Posted July 22, 2014 I'm looking to toggle a selection of layers that has the h- prefix. Found this on the net but it seems to only turn on the layer. Is there anything I missed or any other way? Thanks ( defun c:test () (if LAYGROUPTOGGLE (progn (command "_.-layer" "off" "h-*" "") (setq LAYGROUPTOGGLE 1) ) (progn (command "_.-layer" "on" "*h-*" "") (setq LAYGROUPTOGGLE NIL) ) )) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 22, 2014 Share Posted July 22, 2014 Welcome to CADTutor . This is enough to off layers that are started with h-* I'm looking to toggle a selection of layers that has the h- prefix. (defun c:test () (command "_.-layer" "off" "h-*" "") ) Quote Link to comment Share on other sites More sharing options...
takeanosan Posted July 22, 2014 Author Share Posted July 22, 2014 Ah, I wasn't trying to achieve that. I was rather trying to assign toggle these layers on and off automatically. My idea was to either: -check if those layers are on, then turn it off; check if layers are off, then turn it on -manually create a variable where every time I run the lisp, the value of the variable toggles: where if variable=nil, turn layer off; variable=1, turn layer on Much thanks. Quote Link to comment Share on other sites More sharing options...
pBe Posted July 22, 2014 Share Posted July 22, 2014 Toggle Tharwat, The key here is Toggle my friend Quote Link to comment Share on other sites More sharing options...
pBe Posted July 22, 2014 Share Posted July 22, 2014 Ah, I wasn't trying to achieve that. I was rather trying to assign toggle these layers on and off automatically. My idea was to either: -check if those layers are on, then turn it off; check if layers are off, then turn it on -manually create a variable where every time I run the lisp, the value of the variable toggles: where if variable=nil, turn layer off; variable=1, turn layer on Much thanks. Does it have to be all matching layer names to toggle? what if some of them are turned off and some are not? Quote Link to comment Share on other sites More sharing options...
takeanosan Posted July 22, 2014 Author Share Posted July 22, 2014 Yes, all matching. It does not matter to me if some of them are already on/off. Quote Link to comment Share on other sites More sharing options...
takeanosan Posted July 22, 2014 Author Share Posted July 22, 2014 Owh and thank you Tharwat for the warm welcome. I'm surprised you noticed. =) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 22, 2014 Share Posted July 22, 2014 Try this . (defun c:on-off (/ on_off l nm layers v e) ;; Tharwat 22.July.2014 ;; ;; Toogle Layers that their names is ;; ;; started with h- ;; (defun on_off (code ent) (entmod (subst (cons 62 code) (assoc 62 ent) ent))) (while (setq l (tblnext "LAYER" (not l))) (if (wcmatch (setq nm (cdr (assoc 2 l))) "h-*") (setq layers (cons nm layers)) ) ) (foreach layer layers (if (minusp (setq v (cdr (assoc 62 (setq e (entget (tblobjname "LAYER" layer))))))) (on_off (abs v) e) (on_off (- v) e) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
takeanosan Posted July 22, 2014 Author Share Posted July 22, 2014 I can't seem to make it run, nor do I understand enough coding to check for any mistakes. REGEN does not help. Unloaded all my other lisps so ruling out any conflicts. Here is my list of commands: Command: -LAYERCurrent layer: "0" Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: off Enter name list of layer(s) to turn off or : h-* Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: Command: *Cancel* Command: ON-OFF Command: Command: *Cancel* Command: -LAYER Current layer: "0" Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: off Enter name list of layer(s) to turn off or : *Cancel* Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: on Enter name list of layer(s) to turn on: h-* Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: Command: ON-OFF Anything else I could help out with? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 22, 2014 Share Posted July 22, 2014 I can't seem to make it run, nor do I understand enough coding to check for any mistakes. REGEN does not help. Unloaded all my other lisps so ruling out any conflicts. How did you run the routine ? can you explain the steps ? Quote Link to comment Share on other sites More sharing options...
takeanosan Posted July 22, 2014 Author Share Posted July 22, 2014 drag, drop into AutoCAD. Also tried appload after your question. Quote Link to comment Share on other sites More sharing options...
takeanosan Posted July 22, 2014 Author Share Posted July 22, 2014 Pretty sure I loaded it correctly. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 22, 2014 Share Posted July 22, 2014 drag, drop into AutoCAD. Also tried appload after your question. One of the proper ways as follows : Save the code to any name you want but it good habit to save with the same name of the lisp command and with the extension .lsp Then from autocad call the command appload to load the lisp file then LOAD from the prompted dialog box then close it . Finally type on-off to call the lisp function . Note: you should have layers that started with h- as you have asked the routine for in your first post . Let me now . Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 22, 2014 Share Posted July 22, 2014 Pretty sure I loaded it correctly. Are you sure that you have previous said layers in that drawing ? Upload a sample drawing if you can . Quote Link to comment Share on other sites More sharing options...
pBe Posted July 22, 2014 Share Posted July 22, 2014 Perhaps something as simple as this one (defun c:test nil (if (zerop (setvar "useri1" (Boole 6 (getvar "useri1") 1) ) ) (command "_.-layer" "off" "H-*" "") (command "_.-layer" "on" "H-*" "") ) ) Quote Link to comment Share on other sites More sharing options...
takeanosan Posted July 22, 2014 Author Share Posted July 22, 2014 Thanks for the tips Tharwat. Here is a sample of the drawing: http://sharesend.com/wdkypsb7 pBe, your code works! I'm pretty much pleased with it. Though do you mind explaining? (defun c:test nil (if (zerop ;<<<can't understand this (setvar "useri1" ;I assume this is setting up a new variable (Boole 6 (getvar "useri1") 1) ;<<<also can't understand this ) ) (command "_.-layer" "off" "H-*" "") (command "_.-layer" "on" "H-*" "") ) ) I hope I am not asking too much. Thanks a lot for all the help. Quote Link to comment Share on other sites More sharing options...
pBe Posted July 22, 2014 Share Posted July 22, 2014 Sure (defun c:test nil (if (zerop ;<-- test if value is zero ;<-- T for 0 ;<-- Nil other than 0 (setvar "useri1" ;<-- System Variable where you can store ;<-- an integer [Hence user[b]I[/b]1] I for integer ;<-- Saved in drawing ;<-- Now for Boole, its more complicated ;<-- Click on the link below [by LM] ;<-- What it does is gives the value 1 ;<-- if current is 0 and vice versa (Boole 6 (getvar "useri1") 1) ) ) (command "_.-layer" "off" "H-*" "") (command "_.-layer" "on" "H-*" "") ) ) Boole Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 22, 2014 Share Posted July 22, 2014 My routine did not work for you because the prefix of the your desired layers to toggle are starting with capital letter and not small letter as you have requested in you first post . Change the prefix from h- to H- in my routine and it should work . Quote Link to comment Share on other sites More sharing options...
takeanosan Posted July 22, 2014 Author Share Posted July 22, 2014 Ahhh, silly me. I was oblivious to the case since autoCAD is usually not particular with cases. E.g. during the find command. I would have guessed it is some stupid mistake on my side. Anyway my apologies and once again thanks for all the help. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 22, 2014 Share Posted July 22, 2014 Ahhh, silly me. I was oblivious to the case since autoCAD is usually not particular with cases. E.g. during the find command. I would have guessed it is some stupid mistake on my side. Anyway my apologies and once again thanks for all the help. Its okay . 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.