Maybe this will help you along a bit? MHUPP will no doubt come up with something nicer - he usually does.
Just making assumptions from MHUPPS questions,
The pattern doesn't mater so much here
Adding an X to start with
Adding just the colour code to finish (1 for red, ->254 for grey) - removing -any- suffix number and '-'
Reversed to remove -any- X at the start of the layer and -any- number at the end replaced by'21'
Done this so that newlayname shows how I was building up the new layer name.
Commented out original lines where not needed and additional lines are not indented.
(defun c:lay2x ( / enx idx lay sel col newlayname)
(if (setq sel (ssget "_:L" '((8 . "~X*")))) ;; Select objects if layer doesn't begin with X
(repeat (setq idx (sslength sel)) ;; Loop through selection set
(setq enx (entget (ssname sel (setq idx (1- idx))))
lay (assoc 8 enx)
col (rtos (cdr (assoc 62 enx))) ; get colour as a string
) ; end setq
(setq newlayname (strcat "X" (cdr lay) ) ) ; add X to start
(setq newlayname (vl-string-right-trim "-0123456789" newlayname)) ; trim away suffix numbers and suffix '-'
(setq newlayname (strcat newlayname "-" col)) ; add in colour suffix.
;; (entmod (subst (cons 8 (matchlayer (cdr lay) (strcat (cdr lay) "-PR"))) lay enx))
(entmod (subst (cons 8 (matchlayer (cdr lay) newlayname)) lay enx)) ; update entity definition
) ; end repeat
) ; end if
(princ)
)
(defun c:x2lay ( / enx idx lay sel newlaynbame)
(if (setq sel (ssget "_:L" '((8 . "X*")))) ;; Select layers beginning with X
(repeat (setq idx (sslength sel)) ;; Loop thrpugh selection set
(setq enx (entget (ssname sel (setq idx (1- idx))))
lay (assoc 8 enx)
) ; end setq
(setq newlayname (vl-string-left-trim "X" (cdr lay))) ; trim away X prefix
(setq newlayname (vl-string-right-trim "-0123456789" newlayname)) ; trim away suffix numbers and suffix '-'
(setq newlayname (strcat newlayname "-21")) ; add in '21' suffix as a string.
;; (entmod (subst (cons 8 (matchlayer (cdr lay) (substr (cdr lay) 1 (- (strlen (cdr lay)) 3)))) lay enx))
(entmod (subst (cons 8 (matchlayer (cdr lay) newlayname)) lay enx)) ; update entity definition
) ; end repeat
) ; end if
(princ)
)
(defun matchlayer ( src new )
(or (tblsearch "layer" new)
(entmake
(subst
(cons 2 new)
(cons 2 src)
(vl-remove-if '(lambda ( x ) (member (car x) '(-1 5 102 360))) (entget (tblobjname "layer" src)))
)
)
)
new
)
ps. this wasn't me, I wasn't here.