Lisp to turn on all layers

Lisp to turn on all layers

Anonymous
Not applicable
3,510 Views
8 Replies
Message 1 of 9

Lisp to turn on all layers

Anonymous
Not applicable

Hi, I know this might sound easy, but I am really struggling to write a lisp to do this.

 

How would I write a lisp to turn on all layers?

 

Kind regards

 

Derryck

0 Likes
3,511 Views
8 Replies
Replies (8)
Message 2 of 9

3wood
Advisor
Advisor

(defun C:LON () (command "._-layer" "on" "*" ""))

This defines a new command LON which turns on all layers.

Message 3 of 9

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

How would I write a lisp to turn on all layers?

....


There's a native AutoCAD command LAYON that does that.  If you need it in Lisp terms specifically, for some reason, this would do:

(command "_.layon")

 

But that won't turn on any Layers that are Frozen.  If you might have those, and you want them thawed as well as turned on, you could use the LAA or LAON command [depending on whether you want any Locked Layers Unlocked, too] from my LayerAll.lsp collection [see what the different commands do in their descriptions:]

 

;;;  LayerAll.lsp
;;;  To perform operations On All Layers
(defun C:LAA (); Layers All All [Thawed, Unlocked, On]
  (command "_.layer" "_thaw" "*" "_unlock" "*" "_on" "*" "" "_.regen")
  (princ)
)
(defun C:LAON (); Layers All [Thawed and] On [not Unlocked]
  (command "_.layer" "_thaw" "*" "_on" "*" "" "_.regen")
  (princ)
)
(defun C:LAOF (); Layers All Off [except current]
  (command "_.layer" "_off" "*" "_no" "")
  (princ)
)
(defun C:LAF (); Layers All Frozen [except current]
  (command "_.layer" "_freeze" "*" "_no" "")
  (princ)
)

 

Kent Cooper, AIA
Message 4 of 9

Anonymous
Not applicable

Thanks. This works perfectly.

 

There is just one more thing 🙂 How would I save the state the layers are in before doing this operation, then put the layers back to the original state after this operation?

 

Cheers

 

Derryck

0 Likes
Message 5 of 9

patrick_35
Collaborator
Collaborator

Hi

 

Use LMAN

 

@+

0 Likes
Message 6 of 9

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... How would I save the state the layers are in before doing this operation, then put the layers back to the original state after this operation?

....


With the -LAyer command's stAte option.  Experiment with it manually in the hyphen-prefixed name to get the command-line version [it has sub-options to deal with], and build in saving of a Layer State into the beginning of some of those commands as appropriate.  Presumably it would be into some temporary name, which will need to be Deleted before you can overwrite it if there's a previous version.  You would need a separate command to Restore that State when you're done with whatever you want to do with all Layers turned on.

Kent Cooper, AIA
0 Likes
Message 7 of 9

Jonathan3891
Advisor
Advisor

This displays a dialog box that displays all layers off/frozen/locked


Jonathan Norton
Blog | Linkedin
0 Likes
Message 8 of 9

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... How would I save the state the layers are in before doing this operation, then put the layers back to the original state after this operation?

....


Actually, come to think of it, [duh] if you're turning everything on with either my LAA or LAON or AutoCAD's own LAYON, since those are all single-Layer-command operations, then after you have done whatever you want to do with the Layers all on, you can just use the native command LAYERP to go back to the previous condition, without the need for Saving and Restoring an explicit Layer stAte.

Kent Cooper, AIA
0 Likes
Message 9 of 9

3wood
Advisor
Advisor

Further more, if you want to temporarily turn on / VP Thaw all layers, leave selected object's layer on (can be nested), then restore previous layer status, you can try command LPO in LAYER.vlx.

 

0 Likes