Change layer color to bylayer

Change layer color to bylayer

msarqui
Collaborator Collaborator
1,148 Views
2 Replies
Message 1 of 3

Change layer color to bylayer

msarqui
Collaborator
Collaborator

Hi guys.

 

I am trying to create a function to change the color of layers:

(defun ModLayer (layname laycolor  / doc layers vlalay)
(setq	doc      (vla-get-ActiveDocument (vlax-get-acad-object))
	layers   (vla-get-Layers doc)
);setq

(setq vlalay (vla-item layers layname))
(if laycolor
	(vla-put-color vlalay laycolor)
)
)


(defun c:MLA () ;Change to magenta (ModLayer "0" 6) ;This works )


(defun c:MLA () ;Change to bylayer
(ModLayer "0" 256) ;This give an error: ; error: Automation Error. Invalid argument Color in IAcadLayer::put_Color
)

Any help please?

Thanks

Marcelo

0 Likes
Accepted solutions (1)
1,149 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant
Accepted solution

@msarqui wrote:

.... 

I am trying to create a function to change the color of layers:

....
(defun c:MLA () ;Change to bylayer
(ModLayer "0" 256) ;This give an error: ; error: Automation Error. Invalid argument Color in IAcadLayer::put_Color
)

Any help please?

....


A Layer cannot have ByLayer assigned to it as a color.  Only objects/entities can have ByLayer as their color assignment.  "ByLayer" means the color is taken from the Layer on which the object is drawn -- a Layer is not "drawn" on some [presumably other?] Layer.

 

I believe you would have the same trouble if you tried to assign "ByBlock" [color 0] to a Layer.

Kent Cooper, AIA
0 Likes
Message 3 of 3

msarqui
Collaborator
Collaborator

Hi Kent,
I can see my mistake now.
Thanks for the explanation!

Marcelo

0 Likes