Author Topic: Find & Replace Layer Names?  (Read 3274 times)

0 Members and 1 Guest are viewing this topic.

bman

  • Guest
Find & Replace Layer Names?
« on: September 12, 2005, 02:41:26 PM »
Is there a way to find a layer(s) with a specific string and replace that string globally for multiple layers?

ex.... Find A & Replace with B

A-P-EOP
A-P-BNDY
A-P-CL

Change to this:

B-P-EOP
B-P-BNDY
B-P-CL

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Find & Replace Layer Names?
« Reply #1 on: September 12, 2005, 03:01:18 PM »
Take a look at the rename command.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

bman

  • Guest
Re: Find & Replace Layer Names?
« Reply #2 on: September 12, 2005, 03:26:03 PM »
That works fine for adding a prefix to multiple layers, but I still have to go back & edit & remove the old prefix on about 150 layers.

Bob Wahr

  • Guest
Re: Find & Replace Layer Names?
« Reply #3 on: September 12, 2005, 03:48:25 PM »
in the rename dialog box
in Old Name, type a-*
in rename to, type b-*
click OK,
works fine for me

bman

  • Guest
Re: Find & Replace Layer Names?
« Reply #4 on: September 12, 2005, 05:13:59 PM »
I was selecting the layers in lieu of typing the wildcard :oops:
Thnaks for the tip!

Peter Jamtgaard

  • Guest
Re: Find & Replace Layer Names?
« Reply #5 on: September 12, 2005, 05:50:40 PM »
Try this

Peter Jamtgaard

Code: [Select]
(defun C:RenameLayers ()
 (setq strOld (getstring "\nOld String: ")
       strNew (getstring "\nNew String: ")
 )
 (vlax-for objLayer
           (vla-get-layers
            (vla-get-activedocument
             (vlax-get-acad-object)
            )
           )
  (setq strLayerName (vla-get-name objLayer))
  (if (and
       (/= (vl-string-subst strNew StrOld strLayerName)
            strLayerName
           )
       )
       (not (tblsearch "layer" strLayerName))
      )
   (if
    (vl-catch-all-error-p
     (vl-catch-all-apply
      'vla-put-name
      (list objLayer (vl-string-subst strNew StrOld strLayerName))
     )
    )   
   )
  )
 )

bman

  • Guest
Re: Find & Replace Layer Names?
« Reply #6 on: September 13, 2005, 08:03:43 AM »
I'm getting a syntax error when tryimh to load it

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Find & Replace Layer Names?
« Reply #7 on: September 13, 2005, 08:58:42 AM »
It's not you, the two if statements are malformed. I'm sure Peter will be around to fix it (and the local declarations) shortly -- I think he justed posted it real quick.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Peter Jamtgaard

  • Guest
Re: Find & Replace Layer Names?
« Reply #8 on: September 14, 2005, 08:53:13 AM »
Sorry for the error

Peter

Code: [Select]
(defun C:RenameLayers (/ objLayer strNew strOld )
 (setq strOld (getstring "\nOld String: ")
       strNew (getstring "\nNew String: ")
 )
 (vlax-for objLayer
           (vla-get-layers
            (vla-get-activedocument
             (vlax-get-acad-object)
            )
           )
  (setq strLayerName (vla-get-name objLayer))
  (if (and
       (/= (vl-string-subst strNew StrOld strLayerName)
            strLayerName
       )
       (not (tblsearch "layer" strLayerName))
      )
   
   (vl-catch-all-error-p
    (vl-catch-all-apply
     'vla-put-name       
     (list objLayer (vl-string-subst strNew StrOld strLayerName))
    )
   )
  )
 )
)