Force drawing color in Rhino.NET and RhinoCommon

Hello,

in Rhino.NET I was forcing the drawing color with the code:

OnColor color = new OnColor(0, 255, 0);
RhUtil.RhinoApp().ActiveDoc().Properties().SetCurrentColor(color);
RhUtil.RhinoApp().ActiveDoc().Properties().SetCurrentColorSource(IOn.object_color_source.color_from_object);

I can’t find the equivalent under RhinoCommon. Any Idea?

Thanks. L

In Rhino Common, each object has attributes which save the color source, color etc.

see https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_DocObjects_RhinoObject.htm
and https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_DocObjects_ObjectAttributes.htm

Example:

            RhinoObject rhObj = doc.Objects.Find(objRef.ObjectId);
            rhObj.Attributes.ColorSource = ObjectColorSource.ColorFromObject;

You can create new attributes like this:

             ObjectAttributes attributes = new ObjectAttributes();

or

            ObjectAttributes attributes = new ObjectAttributes
            {
                ColorSource = ObjectColorSource.ColorFromObject,
                ObjectColor = yourColor
            };

And apply it to geometry like this:

            doc.Objects.AddBrep(brep, attributes);
1 Like

Rogers,

thanks. L