layer rename lisp

layer rename lisp

Anonymous
Not applicable
6,254 Views
22 Replies
Message 1 of 23

layer rename lisp

Anonymous
Not applicable
I'm looking for a lisp to automatically add a prefix or suffix to all
existing layer names in a drawing.

--

Jim Hill
Curtis + Ginsberg Architects LLP
www.cplusga.com
0 Likes
6,255 Views
22 Replies
Replies (22)
Message 2 of 23

Anonymous
Not applicable
Easiest order of the day.
--
Eric S. eschneider@jensenprecast.com

(setq old_name "whatever" new_name "something else")
(command "-rename" "layer" old_name new_name)
0 Likes
Message 3 of 23

Anonymous
Not applicable
Thanks, Eric.
Someone else already beat you to the punch, by just reminding me that rename
can be used for that.

--

Jim Hill
Curtis + Ginsberg Architects LLP
www.cplusga.com

"Eric Schneider" wrote in message
news:34B6D460187701BB187F22300F048D87@in.WebX.SaUCah8kaAW...
Easiest order of the day.
--
Eric S. eschneider@jensenprecast.com

(setq old_name "whatever" new_name "something else")
(command "-rename" "layer" old_name new_name)
0 Likes
Message 4 of 23

Anonymous
Not applicable
Do you want to automate this so that you can rename all layers, all at once,
without typing.

A lisp routine would be very easy to automate this.

Jim Hill wrote in message
news:AB3CA71BA2AD7C99AB3FEAC8FD3283F3@in.WebX.SaUCah8kaAW...
> Thanks, Eric.
> Someone else already beat you to the punch, by just reminding me that
rename
> can be used for that.
>
> --
>
> Jim Hill
> Curtis + Ginsberg Architects LLP
> www.cplusga.com
>
> "Eric Schneider" wrote in message
> news:34B6D460187701BB187F22300F048D87@in.WebX.SaUCah8kaAW...
> Easiest order of the day.
> --
> Eric S. eschneider@jensenprecast.com
>
> (setq old_name "whatever" new_name "something else")
> (command "-rename" "layer" old_name new_name)
>
0 Likes
Message 5 of 23

Anonymous
Not applicable
Actually the rename dialogue box was perfect for this situation. I needed
to combine several different floor plans of the same building, each in a
separate dwg file, into one file, placing them directly on top of them so I
could edit them all at the same time, but with the ability to turn them off
by floor to edit one floor at a time too.
Anyway, job's over for now so thanks to all for your input.

--

Jim Hill
Curtis + Ginsberg Architects LLP
www.cplusga.com

"Matt Slay" wrote in message
news:C19227D30A6386F0CA868CAF9D7AAFEC@in.WebX.SaUCah8kaAW...
Do you want to automate this so that you can rename all layers, all at once,
without typing.

A lisp routine would be very easy to automate this.

Jim Hill wrote in message
news:AB3CA71BA2AD7C99AB3FEAC8FD3283F3@in.WebX.SaUCah8kaAW...
> Thanks, Eric.
> Someone else already beat you to the punch, by just reminding me that
rename
> can be used for that.
>
> --
>
> Jim Hill
> Curtis + Ginsberg Architects LLP
> www.cplusga.com
>
> "Eric Schneider" wrote in message
> news:34B6D460187701BB187F22300F048D87@in.WebX.SaUCah8kaAW...
> Easiest order of the day.
> --
> Eric S. eschneider@jensenprecast.com
>
> (setq old_name "whatever" new_name "something else")
> (command "-rename" "layer" old_name new_name)
>
0 Likes
Message 6 of 23

Anonymous
Not applicable
Jim Hill wrote:
>I'm looking for a lisp to automatically add a prefix or suffix to all
>existing layer names in a drawing.

http://xarch.tu-graz.ac.at/autocad/stdlib/STDTBL.LSP

(STD-TBL-NAMES tbl)
(STD-TBL-RENAME tbl old new)
--
Reini Urban
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html
0 Likes
Message 7 of 23

Anonymous
Not applicable
OK I'm looking for a way to drop the prefix. This syntax does not work with the rename command and I don't understand why.

old name = CELL_*
rename to = *

This doesn't work either:
old name = CELL_A*
rename to = A*

This does:
old name = CELL_*
rename to = _*


Doesn't make any sense to me. How do I drop the CELL_?
0 Likes
Message 8 of 23

Anonymous
Not applicable
Testing, I tried this and it worked for me

old name = CELL_*
rename to = *

If it still doesn't work try this
{code}
(defun c:test (/ ln)
(vl-load-com)
(vlax-for lay (vla-get-Layers
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
(setq ln (vla-get-name lay))
(if (wcmatch ln "CELL_*")
(vla-put-name lay (vl-string-left-trim "_" (vl-string-left-trim "CELL" ln)))
;(vla-put-name layer (substr ln 6)
;(vla-put-name lay (vl-string-left-trim "CELL_" ln))
)
)
(princ)
)
{code}

Here's one a little more generic
{code}
(defun c:test (/ pre stlen ln)
(vl-load-com)
(setq pre (getstring "\nEnter prefix to delete: (case sensitive) ")
stlen (strlen pre)
)
(vlax-for lay (vla-get-Layers
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
(setq ln (vla-get-name lay))
(if (wcmatch ln (strcat pre "*"))
(vla-put-name lay (substr ln (1+ stlen)))
)
)
(princ)
)
{code}
0 Likes
Message 9 of 23

Anonymous
Not applicable
I already posted it a week ago...

http://discussion.autodesk.com/forums/thread.jspa?threadID=762649&tstart=60


Re: lisp to rename old layers...?
Posted: Feb 16, 2010 7:13 PM in response to: aUTOCAD_CLIENT
Reply


Add prefix or sufix to layer names PSrename.vlx (12.2 KB)


Check this one out... I guess it works

http://www.xanadu.cz/en/download.asp?file=PSrename
0 Likes
Message 10 of 23

Anonymous
Not applicable
I used your generic one and it works great! Been looking for something like this for a while. AWESOME!
0 Likes
Message 11 of 23

kameron1967
Collaborator
Collaborator

How do you run or edit this routine?

0 Likes
Message 12 of 23

Anonymous
Not applicable

Just sharing an old routine i had for this as well. Could use some cleanup.

This routine is dialog based and includes a search string, adding prefix/suffix, remove string with option to auto merge, string replacement, and "all caps".

 

 Note: If the Search string at the top of the dialog is left empty, changes will apply to all layers.

         

Message 13 of 23

kameron1967
Collaborator
Collaborator

Thanks.  I actually found one also.  I might look into your code to see if there's something that I could use to create NEW layer options based on the first entitfy selected.  I'm trying to add a modifier to a selected entity and anything selected after that first one will all get moved to the new modified layer.  That's my goal at the moment.

0 Likes
Message 14 of 23

stevor
Collaborator
Collaborator
So post what you found, and note where you want to add your modification....Guessing at what you intend, the process might be: select an object, use its layer name to make a relatted layer name, and use that new name to create a layer and to change subsequently selected entities to that new name.... That has been done.
S
0 Likes
Message 15 of 23

kameron1967
Collaborator
Collaborator

This is the code that I was trying to modify.  It simply allows for either a prefix or a suffix.  I have not yet attempted to do it, as it's a bit daunting for me.  But if you say there is already a routine that's already been created, please direct me there.  Thanks!

 

;;  CAB 03.09.07
;;  LayerRename.lsp
;;  Rename selected layers with prefix or suffix
(defun c:Lprefix()
  (LayerRename t)
)
(defun c:Lsuffix()
   (LayerRename nil)
)
;;  Use these to change the string
(defun c:ChgPrefix ()
  (while
    (progn
      (initget 1)
      (setq *prefix (getstring t "\nEnter the prefix: "))
      (= "" *prefix)
    )
    (princ)
  )
)(defun c:ChgSuffix ()
  (while
    (progn
      (initget 1)
      (setq *suffix (getstring t "\nEnter the suffix: "))
      (= "" *suffix)
    )
  )
   (princ)
)


(defun LayerRename (pre / obj lyr newlyr str getlyr)
  (defun GetLayer (Obj)
    (vla-get-name (vla-item (vla-get-layers *doc*) (vla-get-layer Obj)))
  )
  (vl-load-com)
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (or *doc* (setq *doc* (vla-get-activedocument *acad*)))
  (if Pre
    (if (or (null *prefix) (= *prefix "")) (c:ChgPrefix))
    (if (or (null *suffix) (= *suffix "")) (c:ChgSuffix))
  )
  (if Pre
    (setq str *prefix)
    (setq str *suffix)
  )
  (while (setq ent (entsel "\nSelect an object to rename the layer."))
    (setq obj (vlax-ename->vla-object (car ent)))
    (cond
      ((wcmatch (setq lyr (getlayer obj)) "*|*")
       (prompt "\n**  Can not rename a xref layer.")
      )
      ((wcmatch lyr (strcat "*" str "*")) ; potential problems here
       ;;  if the layer name inadvertenlt has the matching string
       (prompt "\n**  This layer is already renamed.")
      )
      (t
       (if Pre (setq newlyr (strcat str lyr)) (setq newlyr (strcat lyr str)))
       (if (vl-catch-all-error-p
             (vl-catch-all-apply
               'vla-put-name
               (list (vla-item (vla-get-layers *doc*) (vla-get-layer Obj))
                     newlyr)))
         (prompt (strcat "\n**  Layer " lyr " could not be renamed."))
         (prompt (strcat "\nLayer " lyr " has been renamed."))
       )
      )
    )
  )
  (princ)
)
(prompt (strcat "\nLayer Rename loaded, Enter LaRn to run."
                "\nEnter ChgSuffix to change the siffix."))
(princ)
0 Likes
Message 16 of 23

Anonymous
Not applicable

Great program, but It returns: "Error: bad argument type: numberp: nil".

0 Likes
Message 17 of 23

DannyNL
Advisor
Advisor

No problems here.

When do you get the error? During loading? During use of one or more of the commands?

0 Likes
Message 18 of 23

Anonymous
Not applicable

Well, I get the error right after you fill in the dialog box and click "OK".  Sometimes it renames  just one layer.  Using AutoCAD 2017.

0 Likes
Message 19 of 23

Anonymous
Not applicable

Never mind.  I just realized I'm responding to the forum of a different program.  Sorry for the mistake, it's just that I was on 4 different forums at the same time about the same subject.

0 Likes
Message 20 of 23

sigmmadesigner
Advocate
Advocate

(defun c:LL ()
(command "layer" "m" "ALVENARIA DE PROJETO" "lt" "continuous" "" "c" "250" "" "")
(command "layer" "m" "ALVENARIA DE DEMOLIÇÃO" "lt" "continuous" "" "c" "1" "" "")
(command "layer" "m" "ALVENARIA DE REFORMA" "lt" "continuous" "" "c" "3" "" "")
(command "layer" "m" "LINHA DE CORTE" "lt" "continuous" "" "c" "4" "" "")
(command "layer" "m" "NBR" "lt" "continuous" "" "c" "4" "" "")
(command "layer" "m" "LINHA DE COTA" "lt" "continuous" "" "c" "252" "" "")
(command "layer" "m" "TRAÇO FINO" "lt" "continuous" "" "c" "252" "" "")
(command "layer" "m" "DETALHE FINO" "lt" "continuous" "" "c" "252" "" "")
(command "layer" "m" "DETALHE MÉDIO" "lt" "continuous" "" "c" "255" "" "")
(command "layer" "m" "TRAÇO MEDIA" "lt" "continuous" "" "c" "7" "" "")
(command "layer" "m" "TEXTO ARIAL" "lt" "continuous" "" "c" "7" "" "")
(command "layer" "m" "TEXTO ROMANS" "lt" "continuous" "" "c" "7" "" "")
(command "layer" "m" "TEXTO TÍTULO" "lt" "continuous" "" "c" "7" "" "")
(command "layer" "m" "JARDINAGEM" "lt" "continuous" "" "c" "79" "" "")
(command "layer" "m" "AREA" "lt" "continuous" "" "c" "1" "" "")
(command "layer" "m" "FORMATO" "lt" "continuous" "" "c" "7" "" "")
(command "layer" "m" "MOBILIARIO" "lt" "continuous" "" "c" "255" "" "")
(command "layer" "m" "HIDRO" "lt" "continuous" "" "c" "255" "" "")
(princ)
)
(defun c:CAMADA ()(C:LL))

0 Likes