Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Mentor
JeffPaulsen
Posts: 776
Registered: ‎09-01-2004
Message 1 of 3 (541 Views)
Accepted Solution

Turn off all frozen layers

541 Views, 2 Replies
02-13-2013 09:16 AM

Hi all. Let me start by saying I'm a real lisp hack.

 

I have an old routine that freezes layers that are off. I would like it to also turn off layers that are frozen. It took a while but I think I figured out how the old routine works. I was having trouble determining how the routine would know if a layer was off or not. I found if the color was a negative number that meant the layer was off  (cond ((< (dxf 62 l) 0) (command "f" (dxf 2 l)))). How do I tell if the layer is frozen?

 

I was also wondering what the character was after the DXF code ie. (dxf 62 l). Is is a lowercase L or an upper case i and what function does it have?

 

Below is the old routine that freezes layers that are off.

 

(defun c:fo (/ l dxf code list)
(defun dxf (code list)
(cdr (assoc code list))
);defun
(setq l (tblnext "layer" T))
(command "LAYER")
(while l
(cond ((< (dxf 62 l) 0) (command "f" (dxf 2 l))))
(setq l (tblnext "layer"))
);while
(command "")
(setq l ())
(cond ((not (null gc)) (gc)))
)

Jeff Paulsen
Civil 3D 2012 SP3 | Win 7 64-bit SP1
Xeon E5-1620 @ 3.60GHz, 16GB Ram | NVidia Quadro 600

JeffPaulsen wrote:

....

I would like it to also turn off layers that are frozen. ....

 

.... How do I tell if the layer is frozen?

 

I was also wondering what the character was after the DXF code ie. (dxf 62 l). Is is a lowercase L or an upper case i and what function does it have?

....

(cond ((< (dxf 62 l) 0) (command "f" (dxf 2 l))))
....


The DXF 70 value for the Layer in the Layer table contains the 1 bit if the Layer is Frozen.  That entry also holds other information about it [locked, Xref-dependent, etc.] in other possible binary bits making up the value, so you can't check for a particular value, but need to check whether 1 is a part of the binary makeup of it.

 

The l is a lower-case L [you can test that by copying it out and pasting it into something with a font that makes the difference obvious].  It is the name of a variable that holds the Layer table data for each Layer as the routine steps through, and the (dxf) subroutine gives the value associated with a particular DXF code in that list.  You could add a condition like this:

 

(cond

  ((< (dxf 62 l) 0) (command "f" (dxf 2 l))); your original to freeze if turned off

  ((= (logand (dxf 70 l) 1) 1) (command "of" (dxf 2 l))); turn off if frozen

); end cond

 

The (logand) function will return 1 if the Layer is frozen, because 1 as a binary bit is part of the makeup of the DXF 70 entry.  So it will be determined to equal 1, and the Freeze option will be applied to that Layer [the Layer name is the DXF 2 value].

 

One nice thing about using (cond) is that it only looks through possible conditions until one is satisfied.  So if it finds a Layer off under the first condition and freezes it, it won't look at the second condition, whether it's frozen.  It doesn't need to, because if it was frozen by the first condition, then it will already be off.  But if it wasn't off, the first condition won't have been satisfied, so it will check whether it's frozen, and if so, turn it off.

*Expert Elite*
Kent1Cooper
Posts: 5,871
Registered: ‎09-13-2004
Message 2 of 3 (537 Views)

Re: Turn off all frozen layers

02-13-2013 09:36 AM in reply to: JeffPaulsen

JeffPaulsen wrote:

....

I would like it to also turn off layers that are frozen. ....

 

.... How do I tell if the layer is frozen?

 

I was also wondering what the character was after the DXF code ie. (dxf 62 l). Is is a lowercase L or an upper case i and what function does it have?

....

(cond ((< (dxf 62 l) 0) (command "f" (dxf 2 l))))
....


The DXF 70 value for the Layer in the Layer table contains the 1 bit if the Layer is Frozen.  That entry also holds other information about it [locked, Xref-dependent, etc.] in other possible binary bits making up the value, so you can't check for a particular value, but need to check whether 1 is a part of the binary makeup of it.

 

The l is a lower-case L [you can test that by copying it out and pasting it into something with a font that makes the difference obvious].  It is the name of a variable that holds the Layer table data for each Layer as the routine steps through, and the (dxf) subroutine gives the value associated with a particular DXF code in that list.  You could add a condition like this:

 

(cond

  ((< (dxf 62 l) 0) (command "f" (dxf 2 l))); your original to freeze if turned off

  ((= (logand (dxf 70 l) 1) 1) (command "of" (dxf 2 l))); turn off if frozen

); end cond

 

The (logand) function will return 1 if the Layer is frozen, because 1 as a binary bit is part of the makeup of the DXF 70 entry.  So it will be determined to equal 1, and the Freeze option will be applied to that Layer [the Layer name is the DXF 2 value].

 

One nice thing about using (cond) is that it only looks through possible conditions until one is satisfied.  So if it finds a Layer off under the first condition and freezes it, it won't look at the second condition, whether it's frozen.  It doesn't need to, because if it was frozen by the first condition, then it will already be off.  But if it wasn't off, the first condition won't have been satisfied, so it will check whether it's frozen, and if so, turn it off.

Kent Cooper
Distinguished Mentor
JeffPaulsen
Posts: 776
Registered: ‎09-01-2004
Message 3 of 3 (527 Views)

Re: Turn off all frozen layers

02-13-2013 10:01 AM in reply to: Kent1Cooper

Works like a charm. Thanks for the detailed explaination.

Jeff Paulsen
Civil 3D 2012 SP3 | Win 7 64-bit SP1
Xeon E5-1620 @ 3.60GHz, 16GB Ram | NVidia Quadro 600
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.