VBA object can not modify TrueColor ColorMethod

VBA object can not modify TrueColor ColorMethod

saboh12617
Contributor Contributor
654 Views
2 Replies
Message 1 of 3

VBA object can not modify TrueColor ColorMethod

saboh12617
Contributor
Contributor

Hello,

 

When i import an iges file in my drawing the objects color are defined in Hard, not by layer.

I would like to change it back to the layer color.

I tried a simple loop like 

 

 For Each obj In acadDoc.ModelSpace
    obj.TrueColor.ColorMethod = acColorMethodByLayer
    'obj.TrueColor = obj.Layer.TrueColor
 Next obj

 

But for some reason when i open the LocalWindow view i see that the loop is not modifying the object color method, which is stuck on "acColorMethodByACI".

 

How can i change this?

I tried also calling the layer color as visible on the commented line but it doesnt work either (since the layer properties returns the layer name and not the actual layer, and i think it would just copy the color, not put an equivalence).

 

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

Norman_Yuan
Mentor
Mentor
Accepted solution

You might want to try this way:

 

Dim clr As AcadAcCmColor 
For Each obj In acadDoc.ModelSpace
    Set clr=obj.TrueColor
    clr.ColorMethod = acColorMethodByLayer
    obj.TrueColor = clr
 Next obj

 

The syntax looks strange, but this is how to do it. Also, pay attention to this line:

 

obj.TrueColor = clr

 

Note: no keywork "Set" preceding!

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

saboh12617
Contributor
Contributor

Thank you it works perfectly, objects colors are back to "ByLayer".

A bit tricky, i would have spent a lot of time figuring it out by myself...

As i understand it, redefining the CAD object TrueColor color method is not sufficient as we need to "recall" the CAD object that its TrueColor property object got modified. Seems like pointers are not updating correctly.

 

Thank you for the workaround.

0 Likes