remove layer name

remove layer name

nychoe1
Advocate Advocate
1,557 Views
3 Replies
Message 1 of 4

remove layer name

nychoe1
Advocate
Advocate

hello guys.

I want to delete all the special characters in the layer name. 
if are there special characters like these   --->     @ $, [, ~, {, ],  etc...
I want to delete all at once.    some help.  is any lsp?
 
always thank you guys...
0 Likes
Accepted solutions (1)
1,558 Views
3 Replies
Replies (3)
Message 2 of 4

dbhunia
Advisor
Advisor

Try this.......

 

 

(defun c:Ren_Lay ( / Lay_name N str)
(vl-load-com)
(vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) 
	(setq Lay_name (vla-get-name layer))
	(setq N 1 str "")
	(repeat (strlen Lay_name)
		(setq val (substr Lay_name N 1))
		(if (or (<= 65 (ascii val) 90)(<= 97 (ascii val) 122)(<= 48 (ascii val) 57)(= 32 (ascii val)))(setq str (strcat str val)));;This will not Remove Space
		;(if (or (<= 65 (ascii val) 90)(<= 97 (ascii val) 122)(<= 48 (ascii val) 57))(setq str (strcat str val)));;This will Remove Space		
		(setq N (1+ N))      
	)
	(vla-put-name layer str)
)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 3 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

Here's another way:

(vl-load-com)
(defun C:SLPC (/ layname fixed); = Strip Layer names of Punctuation Characters
  (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) 
    (setq
      layname (vla-get-name layer)
      fixed (vl-string-translate "~@#$%^&()_+{[}]'." "                 " layname)
        ; replace all such characters with spaces
    ); setq
    (while (wcmatch fixed "* *") (setq fixed (vl-string-subst "" " " fixed)))
      ; remove all spaces [original as well as just-substituted]
    (if
      (and
        (not (tblsearch "layer" fixed)); doesn't duplicate an existing Layer name
        (/= fixed ""); wasn't made of only such characters [reduced to nothing]
      ); and
      (vla-put-name layer fixed); rename it
    ); if
  ); vlax-for
  (princ)
); defun

That (if) part is important to avoid possible errors.

 

I did not include the hyphen  -  character among those to be removed, because it's an integral part of the [US] National CAD Standard way of naming Layers, but you can add it if you like, as long as you also add another space to the string of spaces to substitute.

Kent Cooper, AIA
0 Likes
Message 4 of 4

nychoe1
Advocate
Advocate

thank you so much

0 Likes