View Full Version : Add color object to new layer Lisp
BCrouse
2008-02-25, 06:15 PM
Can someone please help me with this.
My idea is to select one color. By selecting that color, it will prompt you to enter a new layer. After that new layer is created, it then would search the whole dwg for that certain color and add it to the layer.
So if I pick the color 165 and it asks me for a layer name. So I give the name Vacant to that layer and all the object associated with that color will be added to the layer Vacant. Please see attachment.
Thank you,
Brad
aaronic_abacus
2008-02-25, 08:25 PM
;This autolisp program changes all entities of a color to a named layer.
(DEFUN C:CLC ()
(PROMPT "\n*CHANGE LAYER BY COLOR* ")
(SETQ SC (GETINT "\nEnter color of entities to change: "))
(SETQ NL (GETSTRING T "\nEnter new layer: "))
(COMMAND "LAYER" "M" NL "")
(SETQ NENC (CONS 8 NL))
(SETQ FLTR (LIST (CONS 62 SC)))
(SETQ CES (SSGET "X" FLTR))
(SETQ CESL (SSLENGTH CES))
(SETQ CT (- CESL 1))
(SETQ LP 1)
(WHILE LP
(SETQ EN (SSNAME CES CT))
(SETQ CT (- CT 1))
(SETQ ENL (ENTGET EN))
(SETQ ENC (ASSOC 8 ENL))
(SETQ NENL (SUBST NENC ENC ENL))
(ENTMOD NENL)
(IF (< CT 0) (SETQ LP NIL))
);END LP
(PRINC)
);END CLC
BCrouse
2008-02-25, 08:54 PM
;This autolisp program changes all entities of a color to a named layer.
(DEFUN C:CLC ()
(PROMPT "\n*CHANGE LAYER BY COLOR* ")
(SETQ SC (GETINT "\nEnter color of entities to change: "))
(SETQ NL (GETSTRING T "\nEnter new layer: "))
(COMMAND "LAYER" "M" NL "")
(SETQ NENC (CONS 8 NL))
(SETQ FLTR (LIST (CONS 62 SC)))
(SETQ CES (SSGET "X" FLTR))
(SETQ CESL (SSLENGTH CES))
(SETQ CT (- CESL 1))
(SETQ LP 1)
(WHILE LP
(SETQ EN (SSNAME CES CT))
(SETQ CT (- CT 1))
(SETQ ENL (ENTGET EN))
(SETQ ENC (ASSOC 8 ENL))
(SETQ NENL (SUBST NENC ENC ENL))
(ENTMOD NENL)
(IF (< CT 0) (SETQ LP NIL))
);END LP
(PRINC)
);END CLC
Thank you! is there a way to pick the color instead of inputting it?
aaronic_abacus
2008-02-25, 09:06 PM
;This is a revision of CLC.LSP, now allowing the color to be entered by selection.
(DEFUN C:CLC ()
(PROMPT "\n*CHANGE LAYER BY COLOR* ")
(SETQ SCEN (CAR (ENTSEL "\nSelect entity for color: ")))
(SETQ SCENL (ENTGET SCEN))
(SETQ SC (CDR (ASSOC 62 SCENL)))
(SETQ NL (GETSTRING T "\nEnter new layer: "))
(COMMAND "LAYER" "M" NL "")
(SETQ NENC (CONS 8 NL))
(SETQ FLTR (LIST (CONS 62 SC)))
(SETQ CES (SSGET "X" FLTR))
(SETQ CESL (SSLENGTH CES))
(SETQ CT (- CESL 1))
(SETQ LP 1)
(WHILE LP
(SETQ EN (SSNAME CES CT))
(SETQ CT (- CT 1))
(SETQ ENL (ENTGET EN))
(SETQ ENC (ASSOC 8 ENL))
(SETQ NENL (SUBST NENC ENC ENL))
(ENTMOD NENL)
(IF (< CT 0) (SETQ LP NIL))
);END LP
(PRINC)
);END CLC
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.