AutoLISP: Add A Prefix To Layer Names

This routine is a great little routine that allows you to add a prefix to all layer names. Although, It does not allow you add a prefix that already exists in at least one layer name like “A-.” I will try to tweak that in the future.

Here’s how:

RL <enter> to Rename Layer by adding a prefix

Enter the new Prefix (for my example, since I work for an Audio-Visual company, I added “AV-” to my layers)

;This routine will place a Prefix in front of all Layer names ;and rename them.

;Of course, it will not rename Layer "0" or "Defpoints".

(prompt "\nType RL to run.........")

(defun C:RL ( / acadDocument theLayers layName pre)


(setq pre (getstring "\nEnter Layer Prefix : "))

(setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))

(setq theLayers (vla-get-layers acadDocument))

(vlax-map-collection theLayers 'layer-mod)



(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



About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, Customization, Layers, Modifying, TIPS. Bookmark the permalink.

1 Response to AutoLISP: Add A Prefix To Layer Names

  1. Pingback: AutoLISP: Add A Prefix To Layer Names – map4bd

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s