Change surface color retrieved from GetObject

Hello,

I am currently trying to change the color of selected surfaces with GetObject.
When the object is exploded, there is no problem, my code works, but as long as different surfaces are joined, it colors the whole object.

I’ve used this loop to color the object, and I understand that selecting the RhinoObject is the problem, but I couldn’t find a way to change the color of a BrepFace or simply a Surface (go is my GetObject object).

for (int i = 0; i < go.ObjectCount; i++) {
    ObjRef objRef = go.Object(i);
    RhinoObject obj = objRef.Object();
                
    RhinoDoc doc = obj.Document;
    obj.Attributes.ObjectColor = System.Drawing.Color.FromArgb(color.ToArgb());
    obj.Attributes.ColorSource = ObjectColorSource.ColorFromObject;
    obj.CommitChanges();

    doc.Views.Redraw();
}

I am able to retrieve the BrepFace with objRef.Face() and the Surface from the BrepObject but I can’t find any method or attribute that can help me. Any ideas?

Thank you for your answers,
Thomas.

Do you want to change the color of a face in a brep/poysurface to a different color than the rest of the brep/polysurface? That is not possible as far as I am aware.

Yes that’s what I am trying to do.
And is it possible to do it with materials?

Hi @thomas.vincent,

In Rhino 7, you will be able to set individual face colors for a polysurface.

This feature is fairly new in the Rhino WIP, so I don’t have an API that I can reference for you.

In Rhino 6, you can assign individual render materials to a polysurface. Although this feature has been in Rhino 6 for a while, the API was just exposed in the future Rhino 6 SR26.

– Dale

Hello,is it possible to change some surface color of a closed polysurface now? The purpose is to let workmate know what surfaces are updated/ adjusted. Solidworks workmate can change surface color easily but Rhino cannot. Thanks.

Yes, this has been possible since Rhino 7.

Just select the surface and set the color using the Properties panel.

Colorful Box.3dm (106.6 KB)

You can remove per-face colors using the RemovePerFaceColors command.

– Dale

:open_mouth: Oh that is Ctrl+shift click surface to change color! That is cool and thanks.

Hello again, it looks like ctrl+shift click cannot assign material on specific surface of a closed polysurface in rendered mode. For example I have a wall of 6 face with one of the faces in different color, and I will need it for high quality rendering for presentation.

https://youtu.be/g-Dpz8jP5d4?si=F42pu-HJWQCGvWXl

I just found this on youtube, sorry for my stupid question, there is still lots of skills to discover and learn.