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?
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.
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