View Full Version : renaming layers
ali888
15th May 2007, 01:38 am
Hi again,
I have another question to ask. unsure if anyone has done this before. I have layers that i'd like to change or rename. It'd be too much work if i do it one by one. I was thinking if there is a program or coding to do that for AutoCAD 2005.
Thank you in advance
CarlB
15th May 2007, 01:55 am
Have you tried the "rename" command? It allows use of wildcards, which may allow you to reduce the number of steps.
mdbdesign
15th May 2007, 02:11 am
You can use codes to do it but still got to type: name, chose color, linetype... It is easy in Layer Property Manager. Try this.
Or import your own layer set, but still got to create...
kchenault
12th Jan 2010, 05:47 pm
The RENAME command only seems to work for prefixes not suffixes. If it comes at the beginning of a layer name, great. If not, you are out of luck, it won't rename.
rkent
12th Jan 2010, 07:11 pm
The RENAME command only seems to work for prefixes not suffixes. If it comes at the beginning of a layer name, great. If not, you are out of luck, it won't rename.
You are responding to an old post, but you can rename prefix or suffix on layer names.
EX. M-DETL-0001, M-DETL-0002, ...
RENAME
M-DETL-????
TO
M-DETL-????-A
kchenault
12th Jan 2010, 08:08 pm
I realized that it was old, but as I was looking for a solution to batch renaming, these types of threads keep coming up. I have been trying to rename multiple layers such as: *-DEMO to *-DEMO-ALT and it does not work. I have never been able to get the rename command to rename multiple layers by adding a suffix. If someone knows the answer, please let me know.
lpseifert
12th Jan 2010, 10:07 pm
not a whole lot of testing so be careful
(defun C:test ( / aDoc lyrs lyr-name suf)
(vl-load-com)
(setq fil (strcase (getstring "Enter filter: ")));don't forget the wildcard(s)
(setq suf (getstring "Enter suffix: "))
(setq aDoc (vla-get-activedocument (vlax-get-acad-object)))
(setq lyrs (vla-get-layers aDoc))
(vlax-map-collection lyrs 'lyr-add)
(princ)
);defun
(defun lyr-add (lyr)
(setq lyr-name (strcase (vlax-get-property lyr 'Name)))
(if
(wcmatch lyr-name fil)
(vla-put-Name lyr (strcat lyr-name suf))
) ;if
(princ)
);defun
David Bethel
12th Jan 2010, 10:18 pm
A type of merge could also work. Edit the laylist to meet your needs:
(defun c:mergel (/ vlist laylist ss tdef fe fd el)
(setq vlist '(("ELEVATION" . 0) ("THICKNESS" . 0)
("CELTSCALE" . 1) ("CECOLOR" . "BYLAYER")
("CELTYPE" . "BYLAYER")))
(foreach v vlist
(and (getvar (car v))
(setvar (car v) (cdr v))))
(setq laylist '(("OLD-LAYER" . "NEW-LAYER")
("3D-SZG" . "SNEEZE")))
(command "_.LAYER")
(foreach l laylist
(if (not (tblsearch "LAYER" (cdr l)))
(command "_New" (cdr l))))
(command "")
(foreach l laylist
(and (setq ss (ssget "X" (list (cons 8 (car l)))))
(command "_.CHPROP" ss "" "_LA" (cdr l) "")))
(while (setq tdef (tblnext "BLOCK" (not tdef)))
(setq fe (cdr (assoc -2 tdef)))
(entmake tdef)
(while fe
(setq fd (entget fe)
el (cdr (assoc 8 fd)))
(if (assoc el laylist)
(setq fd (subst (cons 8 (cdr (assoc el laylist)))
(assoc 8 fd) fd)))
(entmake fd)
(setq fe (entnext fe)))
(entmake (list (cons 0 "ENDBLK")(cons 8 "0"))))
(prin1))
-David
kchenault
12th Jan 2010, 11:08 pm
Thanks people. I will try them out and let you know how they work.
kchenault
13th Jan 2010, 03:11 pm
lpseifert your lisp routine worked perfectly. It did exactly what I was trying to get rename to do, but couldn't. I wish my lisp skills were to that level, alas they are not. You should show the folks at Autodesk a thing or two about what their routine could be doing. You rock! Thanks a million.
lpseifert
13th Jan 2010, 03:22 pm
You know that adage about blind squirrels and nuts...
kchenault
13th Jan 2010, 03:41 pm
Actually, I don't know that one.
lpseifert
13th Jan 2010, 03:43 pm
http://www.flipkart.com/even-blind-squirrel-finds-nut/1606045822-ktx3fu9uvd
Powered by vBulletin™ Version 4.1.2 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.