Jump to content

LISP Function to Get Layer On Off, Lock, Freeze state and restore them later


MAzri

Recommended Posts

I want to add another layer to my routine to allow saving of layer state for On/off, Lock, Freeze, and restore them back after routine.

 

I got the locked layer part but i could not understand this awesome crazy simple routine by Kent1Copper from Autodesk Forum

(defun GLL (/ lay); = Get Locked Layers
  (while (setq lay (tblnext "layer" (not lay)))
    (if (= (logand (cdr (assoc 70 lay)) 4) 4); locked
      (setq LockedLayers (strcat (cond (LockedLayers) ("")) (cdr (assoc 2 lay)) ","))
    ); if
  ); while
); defun

(defun UAL (); = Unlock All Layers
  (command "_.layer" "_unlock" "*" "")
); defun

(defun RLL () ; = Relock [formerly] Locked Layers
  (command "_.layer" "_lock" LockedLayers "")
); defun

 

Basically, I do not understand this part of code below, where and how it capture the lock/unlock layer state and how i can capture the on/off & freeze layer state

 

(while (setq lay (tblnext "layer" (not lay)))
    (if (= (logand (cdr (assoc 70 lay)) 4) 4); locked
      (setq LockedLayers (strcat (cond (LockedLayers) ("")) (cdr (assoc 2 lay)) ","))
    ); if
  ); while

 

Many thanks in advance.

 

Link to comment
Share on other sites

(while (setq lay (tblnext "layer" (not lay))) ;Process each layer in drawing
  (if (= (logand (cdr (assoc 70 lay)) 4) 4)   ;if layer is locked true
    (setq LockedLayers (strcat (cond (LockedLayers) ("")) (cdr (assoc 2 lay)) ",")) ;if true add layer name to end of string with ,
  ); if
); while

 

Its using dxf code to look at the layers and find what state they are in. 70 is used for frozen locked and a few others I didn't realize but makes sense.

 

lockedlayers would look something like

"0,Layer1,Layer2,Layer4, "

 

So RLL

(command "_.layer" "_lock" "0,Layer1,Layer2,Layer4, " "")

 

-Edit

maybe someone can explain to mean why he is using logand wouldn't this work just the same

(if (= (cdr (assoc 70 lay)) 4) 

 

 

Edited by mhupp
Link to comment
Share on other sites

On 23/12/2022 at 23:15, mhupp said:
(while (setq lay (tblnext "layer" (not lay))) ;Process each layer in drawing
  (if (= (logand (cdr (assoc 70 lay)) 4) 4)   ;if layer is locked true
    (setq LockedLayers (strcat (cond (LockedLayers) ("")) (cdr (assoc 2 lay)) ",")) ;if true add layer name to end of string with ,
  ); if
); while

 

Its using dxf code to look at the layers and find what state they are in. 70 is used for frozen locked and a few others I didn't realize but makes sense.

 

lockedlayers would look something like

"0,Layer1,Layer2,Layer4, "

 

So RLL

(command "_.layer" "_lock" "0,Layer1,Layer2,Layer4, " "")

 

-Edit

maybe someone can explain to mean why he is using logand wouldn't this work just the same

(if (= (cdr (assoc 70 lay)) 4) 

 

 

 

So this is called dxf code. I need to study further on this. Thanks for the explanation.

 

On 24/12/2022 at 05:49, BIGAL said:

Ask him at Forums/autodesk.com/

 

Thanks. I guess I better to ask him there. 

 

ps: i notice the link i made on Kent1Copper name is broken and link back to this thread. Here is the actual page on this

 

 

Link to comment
Share on other sites

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