Possible to color individual BrepFace?

I try to color parts of the surface of a block but I don’t know how.

I thought that from the InstanceDefinition I would get the BrepObject, access its BrepGeometry and finally the BrepFaces. But then, I could not find out how to proceed and set the color. Can someone help me?

What I have:

doc.InstanceDefinitions.Find(block_name, true).GetObjects().Get(0).BrepGeometry.Faces[0]

I believe we’ve added the ability to assign a material to a Brep face in the Rhino WIP. @andy, correct me if I am wrong.

– Dale

You are not wrong.

Thank you, @andy. Does it mean that in the current release it is not possible but later it will maybe? Is there then another way for me to color parts of a block like in the attached mockup now?

Maybe you can color the individual parts and use Group instead of Join?

@menno Do you mean I could group the faces and then assign a color to the group? Could you indicate a code snippet?

Not exactly - you assign color to each face and add it individually to the document. Then use the doc.Groups to group them like so:

IEnumerable<Brep> redParts; // defined elsewhere
List<Guid> redGuids = new List<Guid>();
foreach(var p in redParts)
  Guid g = doc.Objects.AddBrep(p);
  if (g != Guid.Empty) redGuids.Add(g);

doc.Groups.Add("red group", redGuids);

Now you have a group of individual objects that can be selected by the user as a group.

nice, thank you. Could you also give me a hint how to assign the color of a BrepFace? I haven’t found a suitable member or method in the documentation so far.

Hi Jups23

You will need to dig in the RhinoCommon for the wip:

What I could find:


Yet I did not yet found how to set a material per component…

@Andy might be able to shone a light on this.


No. You don’t set it per face but you add each face as a BRep and assign color to it (using a Material).
Use BrepFace.DuplicateFace(true) if necessary.

fine, I just could not find how to assign a material to neither a Rhino.Geometry.Brep nor a Rhino.Geometry.BrepFace. Would I have to put it into an extra layer redLayer and assign a layer material?

You can set a color to an object like so:

ObjectAttributes attr = new ObjectAttributes();
attr.ObjectColor = Color.Red;
attr.ColorSource = ObjectColorSource.ColorFromObject;
doc.Objects.AddBrep(p, attr);

You can assign a material to an object like so:

int redMaterialIndex = doc.Materials.Find("MY_RED_MATERIAL", true);
if (redMaterialIndex < 0) // does not exist yet
    Material m = new Material();
    // there is much more to configure on a material
    // this is just very simple. and red.
    m.DiffuseColor = Color.Red;
    m.Name = "MY_RED_MATERIAL";
    materialIndex = doc.Materials.Add(m);
ObjectAttributes attr = new ObjectAttributes();
attr.MaterialIndex = materialIndex;
attr.MaterialSource = ObjectMaterialSource.MaterialFromObject;
// optionally always show it in rendered mode
doc.Objects.AddBrep(p, attr);
1 Like