renaming layers

Discussion in 'AutoCAD' started by Happy Trails, Feb 24, 2006.

  1. Happy Trails

    Happy Trails Guest

    I receive dwgs from others that have had various revisions of drawings
    added/xrefd/bound/etc etc etc.

    They will (eventually) contain layer names that have had previous
    drawing names prefixed in front of the original layers, with those $'s
    in front.

    My problem is when I import them into another sw pkg the names are too
    long - my limit there is 16 chars.

    So they get truncated.

    So everything that was at some brought in from drawing
    ssg1-sd42-feb-03-06 and has this prefixed to the exploded-whatever
    layer names, all ends up on a layer called "ssg1-sd42-feb-03" in the
    sw I use.

    I can go thru in ACAD and rename all the layers taking the
    ssg1-sd42-feb-03$ off the front of the names, but what I'd really
    like to do is a search-and-replace function on the layer names, and
    tear all the prefixes off.

    It would actually be better for me that all of the "-curb" layers from
    different dwgs all ended up on the same layer too.

    Is there any way I can do this renaming a bit automated in ACAD
    instead of editing them all individually?

    I'm not actually much of an ACAD user, but I always have a copy
    available for cleaning up (or dirtying up) the files I receive before
    importing them to my cad sw of choice.

    Thanks.

    Happy Trails To You
     
    Happy Trails, Feb 24, 2006
    #1
  2. Happy Trails

    Happy Trails Guest

    Thanks Mr. B., but . . .

    .. . . it would be nice if it worked with lower case letters. I tried
    to change it but it still didn't work. It's the first time I ever
    used an autolisp routine ( to my knowledge).

    Would it have this handicap with the underscores and dashes also?



    Happy Trails To You
     
    Happy Trails, Feb 24, 2006
    #2
  3. Happy Trails

    Mr. B Guest

    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
     
    Mr. B, Feb 24, 2006
    #3
  4. Happy Trails

    Mr. B Guest

    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
     
    Mr. B, Feb 25, 2006
    #4
  5. Happy Trails

    Happy Trails Guest


    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
     
    Happy Trails, Feb 25, 2006
    #5
  6. Happy Trails

    Happy Trails Guest

    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
     
    Happy Trails, Feb 26, 2006
    #6
  7. Happy Trails

    Kitty Guest

    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.
     
    Kitty, Feb 26, 2006
    #7
  8. Happy Trails

    Happy Trails Guest

    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
     
    Happy Trails, Mar 5, 2006
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.