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)

(vl-load-com)

(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)

(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)
Advertisements

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.

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s