Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Renaming layers

7 REPLIES 7
Reply
Message 1 of 8
wwydock
489 Views, 7 Replies

Renaming layers

I have some existing drawings that need to have the layers renamed. I have mechanical and plumbing drawings that I have to rename the piping layers. Is there a way to collect all the layers that contain pipe and add MX- or PX- in front of the layer name. I know you can use the rename command to try to do this but there a lot of layers and all layers may not be in each drawing.
7 REPLIES 7
Message 2 of 8
hmsilva
in reply to: wwydock

Hi wwydock,
quick and dirty:

 

(vl-load-com)
(defun c:demo (/ pref) (if (and (setq pref (getstring T "\nEnter layer prefix: ")) (/= pref "") ) (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object) ) ) (if (wcmatch (vla-get-name layer) "*pipe*") (vl-catch-all-apply 'vla-put-name (list layer (strcat pref (vla-get-name layer))) ) ) ) ) (princ) )

 

Hope that helps
Henrique

EESignature

Message 3 of 8
wwydock
in reply to: hmsilva

I tried your code on one of my files, Autocad acted like it completed the task but nothing happened.

Message 4 of 8
Anonymous
in reply to: wwydock

slightly modify the line in which layer name is checked as like below: It will work.

 

(if (wcmatch (strcase (vla-get-name layer)) "*PIPE*")

 

regards,

gsktry

Message 5 of 8
3wood
in reply to: wwydock

If the target is to add a prefix to the layer name as long as it contains "pipe",

You can just use RENAME command, no need an add-on, as shown below:

layer rename.png

Message 6 of 8
paullimapa
in reply to: 3wood

Just download my free Layer Apps from Exchange store

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales |Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 8
gdefilo
in reply to: wwydock

Hi wwydock,

I would suggest you to visit this page:

http://www.cadforum.cz/cadforum_en/download.asp?fileID=1857

It points to a .vlx file page download: the program is named Rrename and it lets you rename layers, layouts, linetypes and blocks using prefixes and suffixes.

I had the same problem as you and that program solved it.

I didn't try it on multiple files: don't know if it will work, but maybe a little script will help.

 

Hope this helps you.

 

Giancarlo

 

Message 8 of 8
Lee_Mac
in reply to: wwydock

Another, for Vanilla AutoLISP:

 

(defun c:prelay ( / d e l p )
    (if (/= "" (setq p (getstring t "\nSpecify prefix: ")))
        (while (setq d (tblnext "layer" (null d)))
            (setq l (cdr (assoc 2 d)))
            (if (and (wcmatch (strcase l) "*PIPE*") (not (wcmatch (strcase l) (strcat (strcase p) "*"))))
                (setq e (entget (tblobjname "layer" l))
                      e (entmod (subst (cons 2 (strcat p l)) (assoc 2 e) e))
                )
            )
        )
    )
    (princ)
)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost