View Full Version : Modify layers by color
kirkm.89518
2008-07-10, 07:18 PM
Does a lisp routine exist that will allow me to change layers with a certain color to another color.
Example: Select all layers that are magenta and change those to red.
ccowgill
2008-07-10, 08:00 PM
Does a lisp routine exist that will allow me to change layers with a certain color to another color.
Example: Select all layers that are magenta and change those to red.
I havnt tested this, I just stole if from another one of my programs and tweaked it
(defun c:colorconvert (/ ss)
(while (setq ss (tblnext "LAYER"))
(if (= (cdr (assoc 62 ss)) 6)
(command "layer" "Color" "1" (cdr (assoc 2 ss)) "")
) ;_ end of if
) ;_ end of while
(tblnext "LAYER" T)
)
Lions60
2008-07-10, 08:15 PM
You can also give this a try if you would like.
(defun C:chglayer ( / acadobject activedocument LayerTable thelist)
(vl-load-com)
(setq acadobject (vlax-get-Acad-Object))
(setq activedocument (vla-get-activedocument acadobject))
(setq LayerTable (vla-get-layers activedocument))
(vlax-for each LayerTable
(if (=(vla-get-color each)6) ;; check each layer for its color and if it is color 6(magenta) then put it in the list
(vla-put-color each 1)));; making the color 1(red)
);defun
(princ)
kirkm.89518
2008-07-11, 07:21 PM
I appreciate the help!
If i were to add multiple color changes, what would the correct format be?
Lions60
2008-07-11, 07:38 PM
With the code shown below you can copy the if statement to check a layer's color and change the color if the statement is true. For every color you want to check for and change you will have an if statement.
(defun C:chglayer ( / acadobject activedocument LayerTable color)
(vl-load-com)
(setq acadobject (vlax-get-Acad-Object))
(setq activedocument (vla-get-activedocument acadobject))
(setq LayerTable (vla-get-layers activedocument))
(vlax-for each LayerTable
(setq color(vla-get-color each))
(if (= color 6);; If color 6(magenta) then
(vla-put-color each 1);; change the color to 1(red)
(if (= color 7);; If color 7(white) then
(vla-put-color each 2);; change color to yellow
);;end of if statement to change white to yellow
);; end of if statement to change the color from magenta to red
);; end of vlax-for statement
);defun
(princ)
ccowgill
2008-07-11, 07:39 PM
I appreciate the help!
If i were to add multiple color changes, what would the correct format be?
(defun c:colorconvert (/ ss)
(while (setq ss (tblnext "LAYER"))
(cond
( (= (cdr (assoc 62 ss)) 6)
(command "layer" "Color" "1" (cdr (assoc 2 ss)) "")
) ;_ end of cond1
((= (cdr (assoc 62 ss)) 5)
(command "layer" "Color" "2" (cdr (assoc 2 ss)) "")
) ;_end of cond2
) ;_end of cond
) ;_ end of while
(tblnext "LAYER" T)
)
you could try the above, just substitute your color numbers that you need swapped for the color numbers that are in the condition, and you can copy each condition statement for additional color swaps
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.