Results 1 to 3 of 3

Thread: AUTO CHANGE LAYER NAME

  1. #1
    Member
    Join Date
    2017-07
    Posts
    6
    Login to Give a bone
    0

    Default AUTO CHANGE LAYER NAME

    so while working on a project we get a set of layers for the project (they remain the same on the stuff we are working on) but the issue that I am running into is that the architect will get drawings from structural and not sure what they are doing. but when I open the new base file it will have some weird name to it.

    example:

    current layer: A-FLOR-PLUM-FLDR
    new layer: X_Base_000_Prelim.Rnd 7$0$X_Base_000_Prelim.Rnd 4$0$A-FLOR-PLUM-FLDR

    or

    current layer: A-FLOR-DOOR-EXTR-E
    new layer: X-Exist Shell_202$0$A-FLOR-DOOR-EXTR-E

    what is happening is that we will get a base that has the "current layer" and then we will get a base a few days later with the "new layer" and then about a week later we will get another base that the layers are changed back to the "current layer". I have requested this to stop and there isn't anything that we will be able to do. so I wanted to find out if there is a lisp to write that will be able to take the new layer and get rid of all the extra junk in the name and have it match the current layer name.

    any and all help is greatly appreciated.
    thank you

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: AUTO CHANGE LAYER NAME

    Welcome to AUGI.

    There's no way to make this automatic, if the prefix is constantly different.

    To do this more quickly when you receive a new drawing, this old routine seems to do the trick:

    Code:
    (vl-load-com)
    
    
    (defun c:LAYREN () (c:LayerRename))
    (defun c:LayerRename
           (/ *error* old new acDoc oLayers i oldName newName)
    
    
      (defun *error* (msg)
        (if acDoc
          (vla-endundomark acDoc)
        )
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
        )
        (princ)
      )
    
    
      (if (and (setq old (getstring T "\nEnter string to replace: "))
               (setq new (getstring T "\nEnter replacement string: "))
          )
        (progn
          (vla-startundomark
            (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
          )
          (setq oLayers (vla-get-layers acDoc))
          (setq i 0)
          (vlax-for x oLayers
            (if (vl-string-search old (setq oldName (vla-get-name x)))
              (if
                (tblsearch "layer"
                           (setq newName (vl-string-subst new old oldName)) ; single replacement only
                )
                 (prompt
                   (strcat
                     "\nLayer \""
                     newName
                     "\" already exists. "
                     "Move all objects, then delete layer \""
                     oldName
                     "\" "
                   )
                 )
                 (progn
                   (vla-put-name x newName)
                   (setq i (1+ i))
                 )
              )
            )
          )
          (prompt
            (strcat "\n"
                    (itoa i)
                    " layer"
                    (if (= 1 i)
                      " "
                      "s "
                    )
                    "renamed. "
            )
          )
        )
      )
    
    
      (*error* nil)
    )

    Example from Command Line:

    Code:
    Command: 
    Command: LAYREN
    Enter string to replace: X_Base_000_Prelim.Rnd 7$0$X_Base_000_Prelim.Rnd 4$0$
    Enter replacement string:
    1 layer renamed.
    Command:
    Note - the replacement string above, was an <Enter> (empty string).


    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Member
    Join Date
    2017-07
    Posts
    6
    Login to Give a bone
    0

    Default Re: AUTO CHANGE LAYER NAME

    thank you very much for this.

    being that I am new to this stuff, is there anywhere that I would need to add the old layer names to the new ones (new ones being the ones that I want to change to the old ones that we want to keep).

    I ask this as they are two different cad files. so maybe word it like this.

    if we have old layer: A-FLOR-PLUM-FLDR and have anything before the "A" is removed?

    I am just trying to understand fully, so I am sorry if there is some stupidity here.

    thanks again

Similar Threads

  1. Auto Select and Change Text
    By nrosati351570 in forum Dot Net API
    Replies: 1
    Last Post: 2013-02-11, 09:28 PM
  2. Replies: 5
    Last Post: 2008-11-27, 06:38 AM
  3. Auto-change xref Layer Settings?
    By paul_mep in forum AutoCAD General
    Replies: 6
    Last Post: 2008-06-06, 07:27 AM
  4. Replies: 6
    Last Post: 2007-05-30, 05:45 PM
  5. Replies: 7
    Last Post: 2006-10-23, 04:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •