; CBLAYR.LSP Change entity color to BYLAYER.;; This program sorts entities by their color, and places all entities with; the same color on a layer whose name is the color number (e.g., entities; with the color # 3 will be placed on a layer named "3").;; The entity color of all entities are changed to "BYLAYER", and the layer; inherits the color of the entities placed on it.;; Essentially, this program was written to eliminate entities with explicit; color properties, in preperation for exporting via DXF to a post-processor; that does not honor color-by-entity. Use at your own risk. (defun C:CBYLAYER ( / ss i hi clayer) (initget 7) (setq maxcolor (getint "\nHighest color number: ")) (setq i 0) (princ "\nConverting entity colors from by-entity to by-layer...") (setq hi (getvar "highlight")) (setq clayer (getvar "clayer")) (setvar "highlight" 0) (setvar "cmdecho" 0) (command ".layer") (repeat maxcolor (command "make" (itoa (setq i (1+ i))) "c" i "")) (command "") (setq i 0) (repeat maxcolor (if (setq ss (ssget "x" (list (cons 62 (setq i (1+ i)))))) (command ".chprop" ss "" "la" (itoa i) "c" "bylayer" ""))) (setvar "highlight" hi) (command ".layer" "s" clayer "") (princ) )
Study this link http://www.cadtutor.net/forum/showthread.php?19161-lisp-for-changing-all-objects-in-a-block-to-layer-quot-0-quot
You can also find some examples on Lee's site on how to acces subentities in a block , some examples are easier to understand than others (for a beginner?) but all are elegantly written.