Re: renaming layers



Here is a LISP routine I wrote several years ago. It allows you to change the START string of all layers. If you want to "trim" the layers, you enter your start string, with NO replacement string. Example:
Orignal Layer name TheirDrawing$$YourDrawing
Enter the Start String: TheirDrawing$$
Enter nothing for replacement string:
End result layer name: YourDrawing
Load it and run it with the command "RenLyr".
Hope it works for you!
ps: you can even do this with Blocks (another routine I wrote)
;; Prog to change the start name of Layers ;; with User Selection sets ;; Written by Bruce Feuchuk - Vancouver, BC - Canada
; ////////////////////////////////// ; LOOP to get Remaining Layer Names ; in Data Base (minus first Layer) ; ///////////////////////////////// (defun otherlyr ( ) (while (setq lyrnam (tblnext "layer")) (progn (setq lyrnn (cdr(assoc 2 lyrnam))) (renamlyr)            ; goto Rename Layer loop );progn );while ); defun
; /////////////////////// ; LOOP to Rename Layers ; /////////////////////// (defun renamlyr ( )
; Layer name minus Old string (length of Old String) (setq lyrminus (substr lyrnn (+ 1 oslen) ))
; Get the Start of Layer Name (length of Old String) (setq lyrstart (substr lyrnn 1 oslen))
; ************************************************************ ; Test for Match of Start of Layer Name vs. Old String ; and Change Layer Name with New String if True ; ************************************************************ (setq newlyrnam (strcat ns lyrminus)) (if (= lyrstart os) (command "rename" "la" lyrnn newlyrnam) ); if ); defun
; ~~~~~~~~~~~~~ ; *** START *** ; ~~~~~~~~~~~~~ (DEFUN C:RenLyr ( / lyrnn lyrnam os osl ns nsl oslen lyrminus lyrstart ) (setvar "cmdecho" 1)
; User to Enter Old/New Strings (converted into UpperCase) (setq osl (strlen (setq os (strcase (getstring t "\nEnter -OLD- Layer START string to Change: "))))) (setq nsl (strlen (setq ns (strcase (getstring t "\nEnter -NEW- Layer START string to Change: "))))) (setq oslen (strlen os))        ; Get Old String length
; find First Layer Name in Data Base (setq lyrnam (tblnext "layer" "T")) (setq lyrnn (cdr(assoc 2 lyrnam))) (renamlyr)                ; goto Rename Layer loop (otherlyr)                ; goto Other Layers Loop
(princ) );defun
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Hmmm... you are right (sadly to say). I've always have my Cap Lock on and I guess files I've gotten also are all in CAPS... so I've never noticed this 'problem'.
I have the STRCASE function in there which should have over come this. OKay... cut and paste this part:
; ************************************************************ ; Test for Match of Start of Layer Name vs. Old String ; and Change Layer Name with New String if True ; ************************************************************ (setq newlyrnam (strcat ns lyrminus)) (if (= (strcase lyrstart) os) (command "rename" "la" lyrnn newlyrnam) ); if ); defun
It is this Line ---> (if (= (strcase lyrstart) os) which needs to be slightly modified. But I belive this will work! All NEW strings you add will be Capitals. But heck... who cares, eh? (:
Regards,
BruceF
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Thanks BruceF, that was a bit better.
It still seems to have a problem with"some of" the dollar signs (that ACAD put in there himself???), so I just left a few of them in there as separators instead of a dash.
I'm always going to Terramodel with this stuff, and Tm makes all layer names upper case anyway, so that's no problem.
When I searched, I found that the Geotools guy from India has a routine that is an editor in a window for the layer names in a dwg, with search & replace string fcns, but that guy used to be such an obnoxious advertiser here I'd rather avoid him for such a simple requirement.
Happy Trails To You
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Happy Trails wrote:

That's too bad, cause I [heart] geotools. Had it not been for advertising, I wouldn't know about them. Even with knowing lisp pretty well, it would take me way too long to write all the routines geotools have. Definately not for the price of geotools.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

I guess you are right. I used to get a laugh out of the way others here got really cranked up about the advertising. It used to be worth a colorful exchange or 2.
Whatever happened to Geotools - haven't seen much lately? Ever since I told those guys here that they shouldn't call them "GEO"tools, since they claimed they did NOT offer tools specifically for surveyors & Civil Engineers for anything specific to processing "earth" quantities, they seem to have disappeared.
Happy Trails To You
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

BruceF
Just as a follow up on this, I just had occasion to use it again on another dwg set, and it worked fine - much faster than all that typing. This one had a lot fewer layers, and I chose replacement strings that would not cause any duplicates to be formed.
Thanks again. What was a nice sidebar was that I learned a bit about the lisp code process.
TomW
Happy Trails To You
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.