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?
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?
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.
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?
int redMaterialIndex = doc.Materials.Find("MY_RED_MATERIAL", true);
if (redMaterialIndex < 0) // does not exist yet
{
Material m = new Material();
m.Default();
// 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
attr.SetDisplayModeOverride(DisplayModeDescription.FindByName("Rendered"));
doc.Objects.AddBrep(p, attr);