Rename Multiple layers

Discussion in 'AutoCAD' started by Tim, Apr 8, 2005.

  1. Tim

    Tim Guest

    is it possible to re-name multiple layers all at once.

    The problem I have is this..we all know that when you bind a x-ref you get
    the x-ref name before the layer name.
    Has anybody come up with a way to strip the x-ref name from the layer name
    so you wind up with your layer standards left.

    I have to convert multiple dwgs (as-builts) to a clients standard before we
    give it to them. And because of the different layer names it makes it real
    hard to run them against a standards checker or layer converter because I
    have to account for a lot more names than just our standards. (i.e. x3grid,
    x5grid etc...)

    Any help or guidance would be greatly appreciated.


    Tim W.
     
    Tim, Apr 8, 2005
    #1
  2. Tim

    T.Willey Guest

    On my machine (A2k4) you can bind the xref as an insert and the layer names are that as if you inserted the drawing.
    Example:
    layer Base|Wall
    became
    Wall

    I think the system variable is "bindtype". For the acad help
    BINDTYPE System Variable
    Concepts Procedures Reference




    Type: Integer
    Not Saved
    Initial value: 0

    Controls how xref names are handled when binding xrefs or editing xrefs in place.


    0 Traditional binding behavior ("xref1|one" becomes "xref$0$one")

    1 Insert-like behavior ("xref1|one" becomes "one")


    Hope that helped, if not a lisp shouldn't be to hard to write.
    Tim
     
    T.Willey, Apr 8, 2005
    #2
  3. Tim

    Joe Burke Guest

    Tim,

    Let's get one thing straight first. If you bind an xref using the "bind" option, it
    works as you described. But is you use the "insert" option the xref layer names are
    removed.

    Given the insert option, if a layer name exists in both files, the layers are merged.
    Otherwise a new layer is created.

    So are you asking how to rename or merge layers which don't exist in both files? So
    you end up with a set of layer names which comply with your company standards?

    Joe Burke
     
    Joe Burke, Apr 8, 2005
    #3
  4. Tim

    Tim Guest

    The dwgs I am working on were already bound a using "bind" so I have to work
    with what I have.

    Is it possible to remove everyting precedding the $0$ in a bunch of layers
    with lisp or a script etc...

    I have a routine that will remove the $0$ but then it adds a x# to the
    beginning of each layer with the # going from say x2 to x8.
    How about removing the first 2 characters from each layer name..is that
    possible...

    I can code the routine to modify the layers but then I have to account for
    all of the different x# values instead of just using our standard layer
    names. Thus the question of being able to remove the x-ref part of the layer
    name

    Thanks guys

    Tim...





    Tim,

    Let's get one thing straight first. If you bind an xref using the "bind"
    option, it
    works as you described. But is you use the "insert" option the xref layer
    names are
    removed.

    Given the insert option, if a layer name exists in both files, the layers
    are merged.
    Otherwise a new layer is created.

    So are you asking how to rename or merge layers which don't exist in both
    files? So
    you end up with a set of layer names which comply with your company
    standards?

    Joe Burke
     
    Tim, Apr 8, 2005
    #4
  5. Tim

    T.Willey Guest

    You can search the string for the last $ character, then grab all the information after that. Something like
    (setq cnt1 -1)
    (while (setq cnt1 (vl-string-search "$" LayName (1+ cnt1)))
    (setq cnt2 cnt1)
    )
    (setq LayName (substr LayName (+ 2 cnt2)))

    From command line prompt

    Command: (setq layname "lksdajfalk$kfj$fkadsl$this is what I want")
    "lksdajfalk$kfj$fkadsl$this is what I want"

    Command: !LayName
    "this is what I want"

    Hope that helps.
    Tim
     
    T.Willey, Apr 8, 2005
    #5
  6. Tim

    Tim Guest

    Here is the adaptation of the code you sent me added into the existing code
    that I had.
    Keep in mind that my lisp skills are somewhat lacking as I am not a
    programmer by any means.
    With that in mind... this obviously does not work so could you look at it
    and let me know where the problem lies

    I certainly appreciate it

    Tim W.



    (DEFUN C:N$ (/ CE record lname LLEN cnt NNAME XNAME YNAME TEST)
    (setq CE (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (setq cnt 0)
    (setq record (tblnext "layer" T))
    (while record
    (setq lname (cdr(assoc 2 record))
    LLEN (- (strlen lname) 3)
    cnt 1 NNAME nil XNAME ""
    )
    (repeat LLEN
    (setq TEST (substr lname cnt 3))
    (if (= TEST "$")
    (progn
    (if (/= XNAME YNAME) (setq cnt -1))

    (while (setq cnt1 (vl-string-search "$" NName (1+ cnt1)))
    (setq cnt2 cnt1)
    )

    (command ".rename" "layer" lname nname)
    )
    (if (null NNAME)(setq XNAME (strcat XNAME (substr lname cnt 1))))
    )
    (setq cnt (1+ cnt))
    ); end repeat
    (setq record (tblnext "layer") YNAME XNAME)
    );end while
    (setvar "cmdecho" CE)
    (princ)
    )
     
    Tim, Apr 8, 2005
    #6
  7. Tim

    T.Willey Guest

    The only thing I don't understand is how you get your prefix for the layers, the x3layername, so I couldn't code that. If you code that and label the number "LayNum" then just add it in, then here is a code that should work.

    Tim

    (defun c:RenameLayers (/ ActDoc LayName cnt1 cnt2 tmpName LayNum)

    (vl-load-com)
    (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (vlax-for Lay (vla-get-Layers ActDoc)
    (setq LayName (vla-get-Name Lay))
    (if (vl-string-search "$" LayName)
    (progn
    (setq cnt1 -1)
    (while (setq cnt1 (vl-string-search "$" LayName (1+ cnt1)))
    (setq cnt2 cnt1)
    )
    (setq tmpName (substr LayName (+ 2 cnt2)))
    (vla-put-Name Lay (strcat LayNum tmpName))
    )
    )
    )
    (princ)
    )
     
    T.Willey, Apr 8, 2005
    #7
  8. What if there's already a layer "this is what I want" in the drawing?
    That's the big potential hangup I see with any automated routine to change
    layer names. Maybe you could take layer $0$whatever, find the whatever part
    from that, and compare it with (tblsearch) for any layer that might already
    be called whatever, then if there is one, LAYMRG $0$whatever into whatever,
    and if there isn't, rename it.
     
    Kent Cooper, AIA, Apr 8, 2005
    #8
  9. Tim

    T.Willey Guest

    Another good point, man you are all over my codes today Kent, but in a good way.

    Tim
     
    T.Willey, Apr 8, 2005
    #9
  10. Tim

    Tim Guest

    When I first open a dwg the layers are the typical {0189A3$0$BLDG-EQ}
    After I run the routine to get rid of $0$ Then I get (X1BLDG-EQ)
    The routine used to work great in 2002 and lower just removing the $0$, now
    it messes up.
    So coding it for the typical xref layer would work.

    I tried running the code and got a "bad argument type: stringp nil"

    Thanks for helping by the way

    Tim




    The only thing I don't understand is how you get your prefix for the layers,
    the x3layername, so I couldn't code that. If you code that and label the
    number "LayNum" then just add it in, then here is a code that should work.

    Tim

    (defun c:RenameLayers (/ ActDoc LayName cnt1 cnt2 tmpName LayNum)

    (vl-load-com)
    (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (vlax-for Lay (vla-get-Layers ActDoc)
    (setq LayName (vla-get-Name Lay))
    (if (vl-string-search "$" LayName)
    (progn
    (setq cnt1 -1)
    (while (setq cnt1 (vl-string-search "$" LayName (1+ cnt1)))
    (setq cnt2 cnt1)
    )
    (setq tmpName (substr LayName (+ 2 cnt2)))
    (vla-put-Name Lay (strcat LayNum tmpName))
    )
    )
    )
    (princ)
    )
     
    Tim, Apr 8, 2005
    #10
  11. Tim

    T.Willey Guest

    That is because the variable "LayNum" is never set in my routine. I didn't know how you got the prefix "x1", so I couldn't code that in. If you tell me how you get it then I can add it, or you could add it.

    Tim
     
    T.Willey, Apr 8, 2005
    #11
  12. Tim

    Tim Guest

    Remember the X# comes only after I run the other routine..So your original
    premise of stripping out everything behind the last $ would work perfectly..
    I would prefer not to run the other routine now if I don't have to.


    Thanks

    Tim
     
    Tim, Apr 8, 2005
    #12
  13. Tim

    T.Willey Guest

    So you don't want to rename the layers with a x# ?
    If so then change this line
    (vla-put-Name Lay (strcat LayNum tmpName))
    to
    (while (tblsearch "layer" tmpName)
    (setq tmpName (strcat tmpName "--VersionFromXref"))
    )
    (vla-put-Name Lay tmpName)

    This will check to make sure the layer name doesn't exist within the drawing, and if it does then it will rename it to have as a suffix "--VersionFromXref".

    Also you can remove LayNum from the variable list.

    Hope I'm understanding you correctly.
    Tim
     
    T.Willey, Apr 8, 2005
    #13
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.