View Full Version : LISP Routine to rename layers to different names.
Is there any LISP routine to rename the existing layers to different names?
I have old drawings and I would like to change the layers' names to AIA style, but I don¡¯t know how I can do it. I haven¡¯t done LISP for over 8 years. If anyone has a file or can anyone guide me how to get a lisp routine?
For your information, all the blocks were created on Layer 0 and put on the proper layers, but I'm not sure it may be affected by renaming the layers
For example, I would change as following;
ARSTAIR --> A-Flor-Strs
ARPARTITION --> A-Flor-Tptn
ARWOOD --> A-Flor-Wdwk
ARFURNITURE --> A-Furn
ARWINDOW --> A-Glaz
Any comments would be appreciated.
You could try a script file utilizing the command line version of the RENAME command. It shouldn't be too difficult.
-rename
la
ARPARTITION
A-Flor-Tptn
-rename
la
ARWOOD
A-Flor-Wdwk
-rename
la
ARFURNITURE
A-Furn
-rename
la
ARWINDOW
A-Glaz
Paste the above into a text file with a SCR extension. You could then drag and drop the script onto your drawings. You could also use Script Pro, depending on your AutoCAD version, to run this on many drawings.
Thanks for your comment.
I didn't know the commend and I haven't used it.
I tried the commend, but it doesn't work if there is any missing layer.
So I think I'd better go with a lisp routine so that it select all layers, checks the layers and rename them.
Thanks a lot!!
Thanks for your comment.
I didn't know the commend and I haven't used it.
I tried the commend, but it doesn't work if there is any missing layer.
So I think I'd better go with a lisp routine so that it select all layers, checks the layers and rename them.
Thanks a lot!!
This is quick and dirty, and minimally tested, but it may get you started:
;;function to rename a layer.
;;if old layer exists, and new layer doesn't exist, the old layer is simply renamed.
;;if old layer exists, and new layer is already there, it takes everything on old layer and puts them on new layer.
;;if old layer doesn't exist, it does nothing.
(defun renlay (ol nl / ss i ent )
(cond ((and (tblsearch "layer" ol) (not (tblsearch "layer" nl)))
(command "._rename" "la" ol nl)
)
((and (tblsearch "layer" ol)(tblsearch "layer" nl))
(setq ss (ssget "x" (list (cons 8 ol))))
(setq i -1)
(repeat (sslength ss)
(setq ent (entget (ssname ss (setq i (1+ i))))
ent (subst (cons 8 nl) (cons 8 (cdr (assoc 8 ent))) ent)
)
(entmod ent)
)
)
((not (tblsearch "layer" ol))
(prompt (strcat "\nLayer " ol " not found. "))
)
)
(princ)
)
;;example
(defun c:test ()
(renlay "ARSTAIR" "A-Flor-Strs")
(renlay "ARPARTITION" "A-Flor-Tptn")
(renlay "ARWOOD" "A-Flor-Wdwk")
(renlay "ARFURNITURE" "A-Furn")
(renlay "ARWINDOW" "A-Glaz")
)
Thanks a lot.
I will try it.
If I can improve it, I will post it.
Thanks for your comment.
I didn't know the commend and I haven't used it.
I tried the commend, but it doesn't work if there is any missing layer.
So I think I'd better go with a lisp routine so that it select all layers, checks the layers and rename them.
Thanks a lot!!
It's not a problem. I would have gone with a lisp routine as well, but didn't have the time to write it out for you.
philpiper
2006-12-14, 10:33 AM
From reading the responses above it sounds like you need to include a "before" and "after" set of layer names in the coding, so that the LISP routine knows what to rename them to. Why not use the LAYER TRANSLATOR within the CAD STANDARDS, built into AutoCAD.
If your list of old drawings has a consistant set of layer names then you only need to open up the first one and create the layer mapping and save it. Then you can reuse it for all the other drawings. We use it all the time for topographical surveys we get in from outside companies and relayer a copy for use as the basis for our site layouts. It's great, as all of our projects then start from the same set of layers, linetypes and colours.
gilsoto13
2009-10-05, 09:04 PM
This is quick and dirty, and minimally tested, but it may get you started:
;;function to rename a layer.
;;if old layer exists, and new layer doesn't exist, the old layer is simply renamed.
;;if old layer exists, and new layer is already there, it takes everything on old layer and puts them on new layer.
;;if old layer doesn't exist, it does nothing.
(defun renlay (ol nl / ss i ent )
(cond ((and (tblsearch "layer" ol) (not (tblsearch "layer" nl)))
(command "._rename" "la" ol nl)
)
((and (tblsearch "layer" ol)(tblsearch "layer" nl))
(setq ss (ssget "x" (list (cons 8 ol))))
(setq i -1)
(repeat (sslength ss)
(setq ent (entget (ssname ss (setq i (1+ i))))
ent (subst (cons 8 nl) (cons 8 (cdr (assoc 8 ent))) ent)
)
(entmod ent)
)
)
((not (tblsearch "layer" ol))
(prompt (strcat "\nLayer " ol " not found. "))
)
)
(princ)
)
;;example
(defun c:test ()
(renlay "ARSTAIR" "A-Flor-Strs")
(renlay "ARPARTITION" "A-Flor-Tptn")
(renlay "ARWOOD" "A-Flor-Wdwk")
(renlay "ARFURNITURE" "A-Furn")
(renlay "ARWINDOW" "A-Glaz")
)
thanks you very much Tim... It will help us in the future... Great!!
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.