Author Topic: working find and replace for autocad layers  (Read 1806 times)

0 Members and 1 Guest are viewing this topic.

Crookedmonk

  • Newt
  • Posts: 30
working find and replace for autocad layers
« on: June 29, 2017, 01:48:04 PM »
Say I have multiple AutoCAD layers:
10 dr1111-ld1
20 dr1111-ld1
etc.

How could I change all dr1111's to say dr2222 at once?

I have tried AutoCAD rename but it does not seem to work even using ##, ** as wildcards.

Any ideas?

Thanks
Monk

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Crookedmonk

  • Newt
  • Posts: 30
Re: working find and replace for autocad layers
« Reply #2 on: June 29, 2017, 03:28:44 PM »
Thank you Cab. But I have seen those:
We are not looking to merge layers (option 1)
We are not working with xrefs. (option 2). I may have completely misunderstood this one, so forgive me if I did.
Rename will only work with Prefix or Suffix (option 3). We are actually looking to change the alfa-numeric section in the middle.

We are more or less looking for a find and replace for layers similar to what you have in many word programs.

Thanks again
Monk

ronjonp

  • Needs a day job
  • Posts: 7529
Re: working find and replace for autocad layers
« Reply #3 on: June 29, 2017, 03:37:08 PM »
Maybe:

Code - Auto/Visual Lisp: [Select]
  1. (defun _rename (find replace)
  2.       (vl-catch-all-apply
  3.         'vla-put-name
  4.         (list x (vl-string-translate find replace (vla-get-name x)))
  5.       )
  6.     )
  7.   )
  8.   (princ)
  9. )
  10. (_rename "dr1111" "dr2222")
« Last Edit: June 29, 2017, 04:02:32 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: working find and replace for autocad layers
« Reply #4 on: June 29, 2017, 05:06:15 PM »
Here is a routine I use for one of my layer problems.

Code - Auto/Visual Lisp: [Select]
  1. ;;  CALayers takes the suffex of layer names like -0 or -1
  2. ;;  and makes it a pre fix like 0- or 1- so the names can be easily
  3. ;;  sorted & floor can be set up in layer manager
  4.  
  5. (defun c:calayers (/ layer str suf l2del)
  6.   (setvar "CLAYER" "0")
  7.   (vlax-for layer (vla-get-layers doc)
  8.     (setq str (vla-get-name layer))
  9.     (if (or (wcmatch str "Camera*") ; delete these objects
  10.             (wcmatch str "Terrain*")
  11.             (wcmatch str "Furniture_*"))
  12.       (setq l2del (cons str l2del))
  13.     (if ;(and (> (strlen str) 1)
  14.       (wcmatch str "*-#") ; last 2 char are a -number
  15.        ;; )
  16.        (progn
  17.          (setq suf (substr str (- (setq slen (strlen str)) 1))
  18.                str (substr str 1 (- slen 2))
  19.                str (strcat (substr suf 2) "-" str)
  20.          )
  21.          (vla-put-name layer str)
  22.        ) ; end progn
  23.     ) ; endif
  24.       ) ; endif
  25.   )
  26.   (if l2del (ARCH:DEL-LAYS doc l2del))
  27.  
  28.   (princ)
  29. )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: working find and replace for autocad layers
« Reply #5 on: June 30, 2017, 02:49:08 AM »
CAB, isn't this:
Code: [Select]
(or (wcmatch str "Camera*") 
    (wcmatch str "Terrain*")
    (wcmatch str "Furniture_*"))

Equal to:
Code: [Select]
(wcmatch str "Camera*,Terrain*,Furniture_*") 
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: working find and replace for autocad layers
« Reply #6 on: June 30, 2017, 10:07:02 AM »
If you click on wcmatch in my previous post you will get the answer.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

jvillarreal

  • Bull Frog
  • Posts: 332
Re: working find and replace for autocad layers
« Reply #7 on: June 30, 2017, 10:32:37 AM »
Old code, but its dialog based, including optional search string, prefix addition, suffix addition, find/replace, merge and uppercase.