Changing layers

Changing layers

Anonymous
Not applicable
542 Views
5 Replies
Message 1 of 6

Changing layers

Anonymous
Not applicable

Tricky problem! I'd like to change all layers called say TG SOME NAME to GHY SOME NAME ie just changing the prefix "TG" to "GHY" and also doing it for all blocks and block attributes so that the prefix TG is changed to GHY and TG layers don't exist anymore oh and preferablly in autolisp which I more or less understand.

0 Likes
Accepted solutions (1)
543 Views
5 Replies
Replies (5)
Message 2 of 6

Shneuph
Collaborator
Collaborator

This seems to work for the layer prefix renaming (minimal testing).  You can use it to try to do something similar for your blocks using the blocks collection.

 

(Defun C:TLC-Change_Layer_Prefix (/)
  (tlf-change_layer_prefix (getstring "\nEnter Old Prefix: ") (getstring "\n Enter New Prefix: "))
  (princ)
  );Defun

(Defun TLF-Change_Layer_Prefix (tlv-OldPrefix tlv-NewPrefix / tlv-layers)
  (setq tlv-layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
  (vlax-for thislayer tlv-layers
    (if (= (strcase (substr (vla-get-name thislayer) 1 (strlen tlv-oldprefix))) (strcase tlv-oldprefix))
      (progn
	(princ (strcat (vla-get-name thislayer) " Changed to: "))(princ)
	(vla-put-name thislayer (strcat tlv-NewPrefix (substr (vla-get-name thislayer) (1+ (strlen tlv-oldprefix)))))
	(princ (vla-get-name thislayer))
	(terpri)
	(princ)
	);progn
      );if
    );vlax-for
  (princ)
  );defun

 

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 3 of 6

paullimapa
Mentor
Mentor
Accepted solution

This routine is not just lisp but like the other poster also uses Vlisp functions.

It'll do more than just prefix but will substitute out all matching (case sensitive) characters in Layer names:

; LyrSub substitutes characters in a layer name
(defun C:LyrSub (/ LAY OBJ STR1 STR2)
 (setq STR1 (getstring "\nEnter Layer Name String to Replace: ")
         STR2 (getstring "\nEnter Layer Name Replacement String: ")
 )
 (vl-load-com)
 (vlax-for OBJ
   (vla-get-layers
    (vla-get-activedocument
     (vlax-get-acad-object)
   )
  )
  (setq LAY (vla-get-name OBJ)
         LAY (vl-string-subst STR2 STR1 LAY)
  )
  (if (not (tblsearch "LAYER" LAY))
   (vl-catch-all-apply
    'vla-put-name (list OBJ LAY)
   )
  )
 )
 (prin1)
)

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 6

Anonymous
Not applicable

Thanks guys much appreciated I'll try both and see what happens !

0 Likes
Message 5 of 6

Anonymous
Not applicable

Yep that works a treat thanks very much, such a nice neat little program too! I'm very impressed!

0 Likes
Message 6 of 6

paullimapa
Mentor
Mentor
0 Likes