It looks like you're new here. If you want to get involved, click one of these buttons!
I am looking for a script that can change the layer of an entity. It must be checked if the layer name ends with -I -W or -E and change to eg same-layername-W, if the layer does not end with -I, -W or -E the entire layer name must be changed to architectural-W. If a layer does not exist, it must be created and the color of layers ending with -W is always 10. The same button for changing to -I (color 7) and to -E (color 102).
I have found this script to remove the -I, -E of -W at the end but it is just the first step:
(defun c:laag-x ( / enx idx lay sel ) (if (setq sel (ssget "_:L" '((-4 . "<or")(8 . "*?-I") (8 . "*?-W") (8 . "*?-E") (-4 . "or>") ))) (repeat (setq idx (sslength sel)) (setq enx (entget (ssname sel (setq idx (1- idx)))) lay (assoc 8 enx) ) (entmod (subst (cons 8 (matchlayer (cdr lay) (substr (cdr lay) 1 (- (strlen (cdr lay)) 2)))) lay enx)) ) ) (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 )
I found this script to put the -W after the layername. But this script does not use the result of the first script, or changes the other entities (without -I, -W and -E) at the end to architectural-W:
(defun c:laag-W ( / e i l n s x ) (if (setq s (ssget "_:L" '((8 . "~*-W")))) (repeat (setq i (sslength s)) (setq x (entget (ssname s (setq i (1- i)))) l (assoc 8 x) n (strcat (cdr l) "-W") ) (if (not (tblsearch "layer" n)) (progn (setq e (entget (tblobjname "layer" (cdr l)))) (entmake (subst (cons 2 n) (assoc 2 e) (subst '(62 . 10) (assoc 62 e) e))) ) ) (entmod (subst (cons 8 n) l x)) ) ) (princ) )
I assume that these two steps can also be done in one go, or that modified entities from the first step (with the shortened layer name) are placed in a new selection set that is used by step 2?