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