LISP to change layer "0" to another layer (existing layer or new layer)

LISP to change layer "0" to another layer (existing layer or new layer)

nichkherbsman
Advocate Advocate
4,450 Views
4 Replies
Message 1 of 5

LISP to change layer "0" to another layer (existing layer or new layer)

nichkherbsman
Advocate
Advocate

LISP to change layer "0" to another layer (existing layer or new layer).

Hi, 

 

I need help, I am looking for lisp that will make all object in layer "0" to another layer (existing or new layer) including layer inside the block.

 

Because I have this drawing that some lines and text and objects are in default layer "0", I want the object in layer 0 to be assign in new layer.

 

Thank you.

NiCHKCiD
BIM Modeler
Technical Officer
Technical Designer
Sr. Draftsman
0 Likes
Accepted solutions (1)
4,451 Views
4 Replies
Replies (4)
Message 2 of 5

doaiena
Collaborator
Collaborator
Accepted solution

I think this will work for you.

(defun c:test ( / ss lay )

(prompt "\nSelect objects from layer 0.")
(if (setq ss (ssget "_:L" '((8 . "0"))))
(progn

(setq lay (getstring "\nEnter a layer name: "))
(if (not (tblsearch "layer" lay))
(command "_.-layer" "_n" lay "")
)
(command "_chprop" ss "" "_LA" lay "")

));if ss
(princ)
);defun
Message 3 of 5

ВeekeeCZ
Consultant
Consultant

@doaienawrote:

I think this will work for you.

(defun c:test ( / ss lay )

(prompt "\nSelect objects from layer 0.")
(if (setq ss (ssget "_:L" '((8 . "0"))))
(progn

(setq lay (getstring T "\nEnter a layer name: "))
(if (not (tblsearch "layer" lay))
(command "_.-layer" "_n" lay "")
)
(command "_chprop" ss "" "_LA" lay "")

));if ss
(princ)
);defun

...also would consider add the select option  "Enter a layer name <select object>: "

0 Likes
Message 4 of 5

cadffm
Consultant
Consultant
A LAYMRG function for Layer0 is handle with care, it is really important to exlude some Blocks (i am sure you dont want to change the layer for all entities in a file 😉 )

Include attributes, Exlude unnamed (non dynamic) blocks, named system-blocks, xrefs..

So if you find one and you can not see or interpret the source code, handle with care.
Test 12x what it do exactly.
Dimensions, tables and more - check it exactly.
Sorry, i can not link to a GOOD tool (which a well exclude list), i am using my own (non public).



Sebastian

0 Likes
Message 5 of 5

nichkherbsman
Advocate
Advocate

Thank you.

NiCHKCiD
BIM Modeler
Technical Officer
Technical Designer
Sr. Draftsman
0 Likes