diff --git a/layerFromColor.lsp b/layerFromColor.lsp index c150301..784eeab 100644 --- a/layerFromColor.lsp +++ b/layerFromColor.lsp @@ -1,20 +1,31 @@ +;; layerFromColor.lsp +;; +;; Create separate layers for each selected objects different colors. +;; +;; Created by Peter Gyetvai +;; gyetpet@mailbox.org + (defun C:LFC (/ i imax il ss currElem color colorNum allColors newLayer currLayer newElem) (graphscr) - ;variables: - (setq i 0);counter to zero - (setq imax 1);while variable - + ; ---------------------------------- prompt ---------------------------------- ; + (prompt "\nselect entities to change layer (all): ") (setq ss (ssget));asks for selection (setq il (sslength ss));length of selection (setq allColors nil) + + ; -------------------------- get colors from objects ------------------------- ; + + (setq i 0);counter to zero + (setq imax 1);while variable + (while imax - (print i) + ;(print i) (setq currElem (entget (ssname ss i) )) (setq color (assoc 62 currElem)) (setq colorNum (cdr color)) - (print colorNum) + ;(print colorNum) (if (and (not (= colorNum 0)) colorNum) (progn @@ -28,24 +39,36 @@ (if (= i il) (setq imax nil));finish function if i equals il ) + ; ----------------------------- create new layers ---------------------------- ; (setq i 0);counter to zero (setq imax 1);while variable (while imax - (print i) + ;(print i) (setq color (nth i allColors)) + + ; --- create new layers --- ; (command "._layer" "_M" color "") + (command "._layer" "_C" color color "") + + (print ) + (princ "Created layer ") + (princ color) + (print ) + ;while specific: (setq i (1+ i));increments i (if (= i (length allColors)) (setq imax nil));finish function if i equals il ) + ; -------------------------------- set layers -------------------------------- ; + (setq i 0);counter to zero (setq imax 1);while variable (while imax - (print i) + ;(print i) (setq currElem (entget (ssname ss i) )) (setq color (assoc 62 currElem)) (setq colorNum (cdr color)) @@ -56,7 +79,6 @@ (setq currLayer (assoc 8 currElem)) (setq newLayer (cons 8 (itoa colorNum))) - (print newLayer) (setq newElem(subst newLayer currLayer currElem)) (entmod newElem) ) @@ -66,6 +88,13 @@ (if (= i il) (setq imax nil));finish function if i equals il ) + ; --------------------------- set color to bylayer --------------------------- ; + + (print ) + (command "_.change" ss "" "_P" "_C" "bylayer" "") + + ; ---------------------------------- finish ---------------------------------- ; + (terpri) (setq ss nil) )