Jump to content

Toggle layer


takeanosan

Recommended Posts

Posted

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)
 )
))

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • takeanosan

    10

  • Tharwat

    8

  • pBe

    4

  • Lee Mac

    1

Top Posters In This Topic

Posted

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-*" "")
 )
 

Posted

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.

Posted

Toggle Tharwat, The key here is Toggle my friend :)

Posted
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?

Posted

Yes, all matching. It does not matter to me if some of them are already on/off.

Posted

Owh and thank you Tharwat for the warm welcome.

I'm surprised you noticed. =)

Posted

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)
)

Posted

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: -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

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

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?

Posted
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 ?

Posted

drag, drop into AutoCAD.

Also tried appload after your question.

Posted

Pretty sure I loaded it correctly.

ocvkDLE.png

Posted
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 .

Posted
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 .

Posted

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-*" "")
 )
)

Posted

Thanks for the tips Tharwat.

Here is a sample of the drawing:

 

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.

Posted

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

Posted

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 .

Posted

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.

Posted
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.

:D

 

Its okay .

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...