Author Topic: Layer Rename  (Read 2878 times)

0 Members and 1 Guest are viewing this topic.

Artisan

  • Guest
Layer Rename
« on: September 22, 2004, 10:34:38 AM »
I really don't know what to call this, but I'll try to explain what I am looking for.

We get surveys in that have hundreds of different layers. We generally filter some out and use only what we need. But to better see what we do, we generally rename the layers with a suffix on the front, like BRE-contour. My question is this. Instead of manually going through and selecting each layer to change, is there a lisp or command that would allow me to select all of the layers at one time and add the suffix to all of them at one time? I have looked around but I haven't come up with anything yet.

Thanks

ronjonp

  • Needs a day job
  • Posts: 7529
Layer Rename
« Reply #1 on: September 22, 2004, 11:17:33 AM »
This doesn't let you select the layers, but it will add a prefix to all.

Code: [Select]
;Adds a specified layer prefix to all layers


(defun C:lprefix ()
  (vl-load-com)
  (setq pre (getstring "\nEnter Layer Prefix : "))
  (setq doc    (vla-get-activedocument
(vlax-get-acad-object)
      )
layers (vla-get-layers doc)
  )
  (vlax-for lay layers
    (setq lname (vla-get-name lay))
    (if (not (member lname '("0" "Defpoints")))
      (vla-put-Name lay (strcat pre lname))
    )
  )
)
(princ)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

M-dub

  • Guest
Layer Rename
« Reply #2 on: September 22, 2004, 11:46:52 AM »
I was just going to add this one I just found at Cadalyst.com.  Haven't tried it yet, but says it will do what you want it to...?

Code: [Select]

;Tip1574:   LYAPPEND.LSP   Append to Layer Name   (c)1999, Paul Bilodeau

(defun C:LYAPPEND ()
  (setq CLY (getvar "CLAYER"))
  (command "-layer" "S" 0 "")
  (setq TX2APND (getstring "\nText to APPEND to Layers: "))
  (setq NXTLAY (tblnext "LAYER" t))
  (setq DWGLLIST NXTLAY)
  (while (/= NXTLAY NIL)
    (setq NXTLAY (tblnext "LAYER"))
    (setq DWGLLIST (append DWGLLIST NXTLAY))
  ) ;end while
  (setq LNUM (length DWGLLIST))
  (setq C70PT (- LNUM 3))
  (setq LYPAIR (- LNUM 4))
  (setq C70NLY (list (cdr (nth C70PT DWGLLIST))
                     (cdr (nth LYPAIR DWGLLIST))
               ) ;_ end of list
  ) ;_ end of setq
  (while C70PT
    (setq C70PT (- C70PT 5))
    (setq LYPAIR (- LYPAIR 5))
    (setq LYN70 (list (cdr (nth C70PT DWGLLIST))
                      (cdr (nth LYPAIR DWGLLIST))
                ) ;_ end of list
    ) ;_ end of setq
    (setq C70NLY (append C70NLY LYN70))
    (if (= C70PT 2)
      (setq C70PT NIL)
    ) ;_ end of if
  ) ;_ end of while
  (setq COUNT (- (length C70NLY) 4))
  (setq RPTCT (/ (- (length C70NLY) 4) 2))
  (setq CHLIST (list (itoa 0)))
  (repeat RPTCT
    (setq CHK70 (nth COUNT C70NLY))
    (setq CHKLY (nth (+ COUNT 1) C70NLY))
    (if (< CHK70 2)
      (progn
        (setq CHLIST (append CHLIST (list CHKLY)))
        (setq COUNT (- COUNT 2))
      ) ;ends progn
      (setq COUNT (- COUNT 2))
    ) ;ends if
  ) ;ends repeat
  (setq CHNUM 1)
  (setq CHRPT (- (length CHLIST) 1))
  (repeat CHRPT
    (setq OLDNM (nth CHNUM CHLIST))
    (setq NEWNM (strcat TX2APND OLDNM))
    (command "rename" "LA" OLDNM NEWNM)
    (setq CHNUM (+ CHNUM 1))
  ) ;ends repeat
 
) ;_ end of defun
(princ "\n Type LYAPPEND to run...")
(princ)

Artisan

  • Guest
Layer Rename
« Reply #3 on: September 22, 2004, 11:50:34 AM »
Thanks guys, I tried the one from ronjonp and it worked great for what we need at this minute. I will give m-dub's a try in a few to see how it works as well. Thanks a lot guys. This place is really helpful!

CADaver

  • Guest
Layer Rename
« Reply #4 on: September 22, 2004, 12:00:43 PM »
Just a note, the RENAME command provides a dialog box that allows the use of wildcards.

bman

  • Guest
Layer Rename
« Reply #5 on: September 22, 2004, 01:18:23 PM »
Wut modifications need to be made to Ronjon's routine to just add the prefix to all layers that are on?

ronjonp

  • Needs a day job
  • Posts: 7529
Layer Rename
« Reply #6 on: September 22, 2004, 01:45:21 PM »
Quote
Wut modifications need to be made to Ronjon's routine to just add the prefix to all layers that are on?


Not my code....I'm just a code thief  :D .

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

sinc

  • Guest
Layer Rename
« Reply #7 on: September 22, 2004, 02:30:31 PM »
Have you tried using the layer translater?  It's particularly useful if you get a drawing that has a slew of layers for objects you want all on one layer.  For example, if someone sends you a drawing with curb on 10 different layers for some reason, and you want all the curb on a single "Curb" layer, the layer translater makes it easy.

You start up the layer translater in the drawing you want to change, load a drawing with your "good" layers in it to use as a template, and then map layers in your "bad" drawing to the layers in your "good" drawing.

bman

  • Guest
Layer Rename
« Reply #8 on: September 22, 2004, 02:44:29 PM »
never even looked at layer translator....but i'll definetly check it out after reading ur post

bman

  • Guest
Layer Rename
« Reply #9 on: September 22, 2004, 02:58:36 PM »
That should be incorporated in the layer dialog. I never knew it existed because it's under ->Tools and I'm mainly in Civil Design. (Guess i should start reading the new features when i upgrade, huh?)
That just saved me a bunch of time...thanks!

PDJ

  • Guest
Layer Rename
« Reply #10 on: September 23, 2004, 08:41:20 PM »
New FEATURES!! We don need no steeking new FEATURES!!

I actually know one guy that still has his side bar menu from back in the R10 and R12 DOS days stuck on the right side of his screen.. Just like it used to be sooooo many years ago..