Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Batch rename layer lisp

Anonymous

Batch rename layer lisp

Anonymous
Not applicable

Hi, I am looking for a lisp to rename over 500 layers to add an extension to them. Rename is too slow for this.

Thanks in advance.
Tony

0 Likes
Reply
Accepted solutions (1)
5,148 Views
10 Replies
Replies (10)

user181
Mentor
Mentor

Here's one from autocad tips website:

 

;This routine will place a Suffix at the end of all Layer names and rename them.
 
;Of course, it will not rename Layer "0" or "Defpoints".
 

(defun C:LRN ( / acadDocument theLayers layName pre)
 
(vl-load-com)
 
(setq pre (getstring "\nEnter Layer Suffix : "))
 
(setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
 
(setq theLayers (vla-get-layers acadDocument))
 
(vlax-map-collection theLayers 'layer-mod)
 
(princ)
 
);defun
 
(defun layer-mod (theLayer)
 
(setq layName (vlax-get-property theLayer 'Name))
 
(if (not (member layName '("0" "Defpoints")))
 
(vla-put-Name thelayer (strcat layName pre))
 
) ;if
 
);defun
 
(princ)

EESignature


0 Likes

Anonymous
Not applicable

Thanks, me being a bit unsure how do I use this?

0 Likes

user181
Mentor
Mentor
Accepted solution

Copy and paste into a notepad document. save it with a name and .lsp extension (newname.lsp)  then use appload command to load it into cad or just drag and drop the .lsp file into autocad drawing area. use LRN at command line to start it. Then follow command line and enter layer suffix and then hit enter

EESignature


0 Likes

Anonymous
Not applicable

Awesome...Thanks!

 

0 Likes

Anonymous
Not applicable

Is there a way to keep the old layers and add the new?

0 Likes

user181
Mentor
Mentor

It would need some modification.  You could post it in the lisp and customization forum HERE and see if someone could modify it. I am unable to modify it. 

EESignature


0 Likes

Anonymous
Not applicable

Thats fine..Thanks!

0 Likes

Rpunturi
Participant
Participant

is there a way to identify when the lisp routine chooses to put the suffix at the end. 

I would like to modify this so it will add it to the beginning. 

 

 

0 Likes

user181
Mentor
Mentor

Try this:

 

;This routine will place a Prefix at the beginning of all Layer names and rename them.
 
;Of course, it will not rename Layer "0" or "Defpoints".
 

(defun C:LRN ( / acadDocument theLayers layName pre)
 
(vl-load-com)
 
(setq pre (getstring "\nEnter Layer Suffix : "))
 
(setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
 
(setq theLayers (vla-get-layers acadDocument))
 
(vlax-map-collection theLayers 'layer-mod)
 
(princ)
 
);defun
 
(defun layer-mod (theLayer)
 
(setq layName (vlax-get-property theLayer 'Name))
 
(if (not (member layName '("0" "Defpoints")))
 
(vla-put-Name thelayer (strcat pre layName))
 
) ;if
 
);defun
 
(princ)

EESignature


0 Likes

Rpunturi
Participant
Participant

works perfectly. 

thank you. Very helpful. 

 

 

0 Likes