See the top rated post in this thread. Click here

Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 36

Thread: Remove $0$ and everything before from Layer names

  1. #21
    The Silent Type Mike.Perry's Avatar
    Join Date
    2000-11
    Posts
    13,656
    Login to Give a bone
    0

    Default Re: Remove $0$ and everything before from Layer names

    Quote Originally Posted by johnh.101098
    so everytime i get a drawing from joe pie his layers have a routine that get translated through this routine from say...

    point-dumb to pnt-misc
    x-epcurb to x-curb
    x-ep to x-eop
    Hi

    Take a look at the AutoCAD command _.LayTrans

    Have a good one, Mike

  2. #22
    AUGI Addict sinc's Avatar
    Join Date
    2004-02
    Location
    Colorado
    Posts
    1,986
    Login to Give a bone
    0

    Default Re: Remove $0$ and everything before from Layer names

    Quote Originally Posted by johnh.101098
    layertranslater is great if both drawings have the same layer names... however mapping every time you translate sucks
    If you always do the same translation (i.e., someone regularly sends you drawings, and they always use the same layer names, and you always want them changed to your layer names, which also are always the same), then you can just save the mapping as a DWS file. Then just load the DWS file into Layer Translator and hit "Translate" - nice and painless.

  3. #23
    Member
    Join Date
    2000-11
    Posts
    11
    Login to Give a bone
    0

    Default Re: Remove $0$ and everything before from Layer names

    is there a way to easily modify this lisp routine to find replace *_* to *-*

  4. #24
    Active Member
    Join Date
    2005-03
    Location
    From Kerala, Currently located at Bangalore, India
    Posts
    95
    Login to Give a bone
    0

    Question Re: Remove $0$ and everything before from Layer names

    Quote Originally Posted by CAB2k View Post
    Perhaps this will help.
    Code:
    ;;;=======================[ LayerXrename.lsp ]======================= 
    ;;; Author:  Charles Alan Butler 
    ;;; Version:  1.0 jan. 10, 2006
    ;;; Purpose: Rename Bound xref layers  $0$ to X1-Layername
    ;;; Sub_Routines: -None 
    ;;;==============================================================
    (defun c:layerxrename (/ usercmd lnamelst laylst x newname prefix prefixcnt tmp)
      (vl-load-com)
      (setq usercmd (getvar "CMDECHO"))
      (setvar "CMDECHO" 0)
      (setq laylst (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
      (vlax-for x laylst
        (setq lnamelst (cons (list (vla-get-name x) x) lnamelst))
      )
    
      (setq lnamelst (vl-sort lnamelst '(lambda (e1 e2) (< (car e1) (car e2)))))
      (setq prefix ""
            prefixcnt 0
      )
      (foreach x lnamelst
        (if (wcmatch (car x) "*$*$*") ; rename the layer
          (progn
            (if (/= (setq tmp (substr (car x) 1 (vl-string-search "$" (car x)))) prefix)
              (setq prefixcnt (1+ prefixcnt)
                    prefix tmp)
            )
            (setq newname (strcat "X" (itoa prefixcnt)  "-"
                                  (substr (car x) (+ 4 (vl-string-search "$0$" (car x))))
                          )
            )
            (vl-catch-all-apply 'vla-put-name (list (cadr x) newname))
          )
        )
    
      )
      (setvar "CMDECHO" usercmd)
      (princ)
    )
    (prompt "\nXref Layer Rename removes $0$, Enter LayerXrename to run.")
    (princ)
    I am a beginner in Lisp. So please tolerate.....
    Can you please alter this code so as to rename the layers like
    GroundFloorPlan$0$A-ANNO-DIMS to A-ANNO-DIMS?

    But in that case it has to check;
    If
    the layer A-ANNO-DIMS already exists, and if so it has to merge GroundFloorPlan$0$A-ANNO-DIMS to A-ANNO-DIMS.
    Else
    Rename it to A-ANNO-DIMS

    Could you please help me out in this?

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

    Default Re: Remove $0$ and everything before from Layer names

    Quote Originally Posted by jhaagen View Post
    is there a way to easily modify this lisp routine to find replace *_* to *-*
    Perhaps, like so:
    Code:
    (vl-load-com)
    (setq TestString "This_Is_a_Test")
    (while (vl-string-search "_" TestString)
      (setq TestString (vl-string-subst "-" "_" TestString)))
    "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

  6. #26
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Remove $0$ and everything before from Layer names

    One more way, but only works for single character replacement...

    Code:
    ((lambda (str)
       (if (eq (type str) 'STR)
         (vl-list->string
           (mapcar (function (lambda (s)
                               (if (eq 95 s)
                                 45
                                 s
                               )
                             )
                   )
                   (vl-string->list str)
           )
         )
       )
     )
      "Pizza_And_Beer"
    )
    The main purpose for showing this is that it's a lot faster than searching through a list with vl-string-search.

  7. #27
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Remove $0$ and everything before from Layer names

    Quote Originally Posted by harilalmn View Post
    I am a beginner in Lisp. So please tolerate.....
    Can you please alter this code so as to rename the layers like
    GroundFloorPlan$0$A-ANNO-DIMS to A-ANNO-DIMS?

    But in that case it has to check;
    If
    the layer A-ANNO-DIMS already exists, and if so it has to merge GroundFloorPlan$0$A-ANNO-DIMS to A-ANNO-DIMS.
    Else
    Rename it to A-ANNO-DIMS

    Could you please help me out in this?
    Here's mine, which does what you're referring to:
    Code:
    (vl-load-com)
    (defun c:LayerClean (/ layers lo name badlayers name1 pos)
      (setvar "CLAYER" "0")
      (setq layers (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))
      (vlax-for lo layers
        (setq name (vla-get-Name lo))
        (cond
          ((and (vl-string-search "$" name) (not (vl-string-search "|" name)))
           (setq badlayers (cons name badlayers))
          )
        )
      )
    
      (foreach name badlayers
        (setq name1 name
              lo (vla-Item layers name)
        )
        (while (setq pos (vl-string-search "$" name1))
          (setq name1 (substr name1 (+ pos 2)))
        )
        (cond
          ((tblsearch "LAYER" name1)
           (command "-LAYMRG" "_Name" name "" "_Name" name1 "_Yes")
          )
          (t
           (vla-put-Name lo name1)
          )
        )
      )
      (princ)
    )
    Edit: As for the other question about "_" to "-", change the check for "$" to "_" - but also it would need a slightly different portion for calculating the new name. Instead of:
    Code:
    (while (setq pos (vl-string-search "$" name1))
          (setq name1 (substr name1 (+ pos 2)))
        )
    You should have:
    Code:
    (setq name1 (vl-list->string (subst (ascii "-") (ascii "_") (vl-string->list name))))
    Last edited by irneb; 2010-08-25 at 12:55 PM.

  8. #28
    Member
    Join Date
    2008-04
    Posts
    25
    Login to Give a bone
    0

    Default Re: Remove $0$ and everything before from Layer names

    I love this place!
    I just ran into this exact problem!
    I'm adding this routine to my toolbars & Tool Palettes.
    Thanks,
    Greg D.

  9. #29
    Member
    Join Date
    2001-03
    Posts
    6
    Login to Give a bone
    0

    Default Re: Remove $0$ and everything before from Layer names

    This lisp rocks! Could you give me a hint how to modify it to pass through Autocad Architecture STYLES and rename those too?

    Thanks in advance.

    Steve in Alaska

  10. #30
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Remove $0$ and everything before from Layer names

    You're all welcome.

    It's a bit more involved when it comes to styles. Unfortunately there no such command as DimStyleMerge, TextStyleMerge or LinetypeStyleMerge. The renaming portion might work normally, but with this scenario there's a high probability of 2 (or more) styles becoming one in the end - which would make rename only possible for the 1st style. As for ACA styles, I've not done much work in ACA as yet (more into Revit for that type of drawing work) - so I can't say with certainty it's going to be easy. The ACA (e.g. Wall) styles may just be saved as dictionaries (like the MLeader styles are) instead of tables (as the Layers, Linetypes, Text & Dimstyles are).

    Which means the lisp will have to step through the entire DWG (including all the blocks) and modify each entity to the required style, then purge the wrong style from the DWG. BTW, that's what the LayMrg command does with layers.

Page 3 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. Replies: 11
    Last Post: 2009-02-27, 04:25 PM
  2. Replies: 6
    Last Post: 2007-05-30, 02:02 PM
  3. Replies: 2
    Last Post: 2007-01-09, 06:39 AM
  4. Change Layer names to other Layer names via a script?
    By tburke in forum AutoCAD Customization
    Replies: 5
    Last Post: 2006-12-04, 07:30 PM
  5. Replies: 12
    Last Post: 2006-10-06, 07:07 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
  •