Lisp to delete a specific layer

Lisp to delete a specific layer

s_pongpaitoon
Explorer Explorer
1,621 Views
5 Replies
Message 1 of 6

Lisp to delete a specific layer

s_pongpaitoon
Explorer
Explorer

Hi all, I'm quite new for Lisp. Wondering if we have any Lisp script for deleting a specific layer e.g. "Layer A" no matter it contains objects or not? This script will be one of the steps in the program that I have been trying to develop.

 

Thanks in advance!!

0 Likes
1,622 Views
5 Replies
Replies (5)
Message 2 of 6

komondormrex
Mentor
Mentor

hey,

 

 

(if (setq to_erase_sset (ssget "_x" '((8 . "Target_Layer"))))
	(command "_erase" to_erase_sset  "")
)
(vla-delete (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "Target_Layer"))

 

target_layer can't be active layer, layer "0"...

 

0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant

(command "_.laydel" "_name" "Layer A" "" "_yes")

 

[By the way, it's not a Script.  That word has a specific, and different though related, meaning in AutoCAD, and AutoLisp routines are not Scripts.  You could do it in Script format, if that's really what you need.]

Kent Cooper, AIA
0 Likes
Message 4 of 6

pendean
Community Legend
Community Legend
@s_pongpaitoon Why not just LAYMRG unwanted layers with layer 0 and call it a day?
0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@pendean wrote:
.... just LAYMRG unwanted layers with layer 0 ....

That will leave any objects that were drawn on that Layer in the drawing [though moved to a different Layer].  I'm not positive, but I think they want to remove them all.  @s_pongpaitoon, is that your intent?

 

As for @komondormrex 's suggestion in Message 2, it will remove things on that Layer only in the current space, and not any that are nested in blocks.  So if there's anything in other than the current space or inside a Block definition, the removal of the Layer itself will fail.

 

LAYDEL removes everything, in all spaces, inside Blocks, etc.

Kent Cooper, AIA
0 Likes
Message 6 of 6

komondormrex
Mentor
Mentor

@Kent1Cooper

i think the op may himself decide which way he will starting to develop his program) 

0 Likes