Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AutoLISP to change the color of a list of layers

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
3659 Views, 6 Replies

AutoLISP to change the color of a list of layers

we get files from architects and we need to add items to certain layers. When I open a file, I would like to be able to run a command that will change the color of a list of layers (say.. RENO1, RENO2, RENO3, NEW1, NEW2, NEW3). I would like to change them all to yellow without having to scroll through the long list of layers and hand changing them. Also if I wanted to add some layers to the change, I would like to be able to simply add a line to the code. How can I accomplish this?

6 REPLIES 6
Message 2 of 7
dlanorh
in reply to: Anonymous

Try this

 

(vl-load-com)
(defun c:CLC ( / c_doc c_lyrs l_lst lyr) (setq c_doc (vla-get-activedocument (vlax-get-acad-object)) c_lyrs (vla-get-layers c_doc) l_lst (list "RENO1" "RENO2" "RENO3" "NEW1" "NEW2" "NEW3") ) (vlax-for lyr c_lyrs (if (vl-position (strcase (vlax-get-property lyr 'name)) l_lst) (vlax-put-property lyr 'color 2)) ) );end_defun

Put your layers names into l_lst in UPPERCASE

 

Edited to update code

I am not one of the robots you're looking for

Message 3 of 7
Kent1Cooper
in reply to: Anonymous

This is simpler than you may think.  The command-line version of the Layer command [which is what you get when it's inside an AutoLisp (command) function] can assign the same color [or other property] to multiple Layers at once, in a comma-delimited string of names:

 

(command "_.layer" "_color" 2 "RENO1,RENO2,RENO3,NEW1,NEW2,NEW3" "")

 

Or in macro-command format that you can put into something like a Tool Palette button:

 

'-Layer Color 2 RENO1,RENO2,RENO3,NEW1,NEW2,NEW3 ;

 

[That one uses the hyphen prefix to suppress the dialog box, and the apostrophe makes it transparent, so you could even invoke it when in the middle of another command.]

 

Add as many more Layer names in the same fashion as you like.

Kent Cooper, AIA
Message 4 of 7
Anonymous
in reply to: Kent1Cooper

Kent, this is exactly what I was looking for. Thank you!

I'm still pretty new to Autolisp and I can't get the syntax down. Is it easy to have the command say "change everything BUT these specific layers to black"?

Message 5 of 7
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

.... Is it easy to have the command say "change everything BUT these specific layers to black"?


 

If you want "these specific layers" to be all the same color as each other, it would be easy to change all  Layers to black, and then change those to the other color.  Would that do?

Kent Cooper, AIA
Message 6 of 7
Anonymous
in reply to: Kent1Cooper

Well the idea was to change everything in the file to color 8 then bring out our layers with different colors. I'm not sure if it works the same to have a command turn everything to 8 then change our layers to whatever color we wanted.

Message 7 of 7
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

.... I'm not sure if it works the same to have a command turn everything to 8 then change our layers to whatever color we wanted.


Yes, that would be the way to go, as in your other thread.  It would also be possible to do something similar to Message 2 here, but checking whether a Layer name is not  in the list before changing the Layer's color.  Then you would need to include only the color you want to change all-other Layers to in the routine, and not the original colors of Layers to change back [because you wouldn't change them to that all-others color].

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report