Author Topic: ranaming layers  (Read 3519 times)

0 Members and 1 Guest are viewing this topic.

DEVITG

  • Bull Frog
  • Posts: 481
ranaming layers
« on: July 06, 2005, 09:49:05 PM »
Hi all , I was loking for a way to change or rename the Layers names , by lisp .
If I had a lot off layers and want to add a prefix to them , how can I do it???

Thanks in advance.
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
ranaming layers
« Reply #1 on: July 06, 2005, 11:15:17 PM »
Here's one way....probably could use a check to make sure the new name is a valid name.
Code: [Select]

(defun c:layprefix (/ lays pre newname)
  (vl-load-com)
  (if (setq lays (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
   pre (getstring "\nNew layer prefix for all layers?: ")
   )
    (progn
      (vlax-for lay lays
(setq newname (strcat pre (vla-get-name lay)))
(if (and (not (eq (vla-get-name lay) "0"));can't rename layer 0
(vl-catch-all-error-p
  (vl-catch-all-apply '(lambda ()
 (vla-item lays newname))
    nil);this checks to ensure the name doesn't already exist
  )
)
 (vla-put-name lay newname)
 )
)
      )
    )
  (princ)
  )

DEVITG

  • Bull Frog
  • Posts: 481
renaming layer
« Reply #2 on: July 07, 2005, 06:46:50 AM »
Hi Jeff , thanks for it .
It will help me understand the MAGIC world of VL .
 :lol:  :)  :D  :shock:  :?  :wink:
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

daron

  • Guest
ranaming layers
« Reply #3 on: July 07, 2005, 07:45:21 AM »
Devit, in my opinion, the best part to figure out the MAGIC world of VL starts here: (vlax-get-acad-object).
Type that into the vlide, highlight it and inspect it. You should find lots of options/directions you can go.

CADaver

  • Guest
ranaming layers
« Reply #4 on: July 07, 2005, 06:58:21 PM »
The RENAME command does that without lisp.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: ranaming layers
« Reply #5 on: July 07, 2005, 08:24:32 PM »
Quote from: CADaver
The RENAME command does that without lisp.

Quote from: DEVITG
Hi all , I was loking for a way to change or rename the Layers names , by lisp . If I had a lot off layers and want to add a prefix to them , how can I do it???
Thanks in advance.

2 things Randy. First, they specifically asked for lisp, maybe to include in something bigger. Second, and more importantly, Rename does not accept wildcards for use with more than 1 item at a time......
Here's my Command line when trying:
Command: -rename
Enter object type to rename
[Block/Dimstyle/LAyer/LType/Style/Ucs/VIew/VPort]: la

Enter old layer name: Corps*

Invalid layer name.

So if I want to add a prefix to all of my layers that begin with Corps, Rename is not quite the tool needed.

CADaver

  • Guest
Re: ranaming layers
« Reply #6 on: July 08, 2005, 11:17:55 AM »
Quote from: Jeff_M
2 things Randy. First, they specifically asked for lisp, maybe to include in something bigger. Second, and more importantly, Rename does not accept wildcards for use with more than 1 item at a time......
Here's my Command line when trying:
Command: -rename
...
So if I want to add a prefix to all of my layers that begin with Corps, Rename is not quite the tool needed.
RENAME will do EXACTLY that, not -rename, but RENAME.  It will allow wildcards:





and accomplish the OP's desire (add a prefix) without lisp.  If you wish to write lisp to do what ACAD already does, go right ahead.  But other than a learning tool, I don't see the point.

AVCAD

  • Guest
Re: ranaming layers
« Reply #7 on: November 07, 2007, 12:27:09 PM »
Not to bring back a almost 3 year topic...but...

I am looking to do something similar also and the rename tool in ACAD is useful yes but when you have too use it on a whole bunch of drawings in a package...say my current project 800 sheets going into each one is very time consuming. You also can not rename a layer say from:

prefix_layer1

too

Layer1

unless you do each layer individually, It would be nice to have a script that would be able to look for a certain string in the layer name and get rid of it, and for that matter if the layer your are trying to change already has that layer in the drawing would just add it to that layer without having to manually do that as well.

ex.

prefix_layer1   ---->   change to Layer1  --->  Layer1 already exists  ---->  Move objects on prefix_layer1 to Layer1