Hi @dale I’m opening a new topic related to this, because I’m finding that I cannot access face materials when opening a headless Rhino and I wanted to check with you if this is normal behaviour.
The following code:
obj = document.Objects.FindId(System.Guid('c9cb3490-c171-47fb-b41d-da3d04e28af8'))
for ci in obj.SubobjectMaterialComponents:
face_mat = obj.GetMaterial(ci)
print(ci.Index, ci.ComponentIndexType, face_mat, face_mat.Id)
works differently if the document is an active open model or a headless opened document, that is:
If I am in an empty document and load another document in headless mode with:
I want to compare face material data between versions of a Rhino file so I need to open both versions in headless mode to do that. For geometry comparissons and attribute data, everything works as expected, but with material data it does not.
Following on, I tried the same code in C# in the Script Editor just to rule out any Python quirk and I get the same behaviour, that is:
if the document is opened it reports the per face material, if not, only the object’s material is reported and the per face material is ignored.
using System;
using Rhino;
string file_path = "C:\\Temp\\01_Textures.3dm";
RhinoDoc document = Rhino.RhinoDoc.OpenHeadless(file_path);
Guid guid = System.Guid.Parse("c9cb3490-c171-47fb-b41d-da3d04e28af8");
Console.Out.WriteLine(guid);
Rhino.DocObjects.RhinoObject obj = document.Objects.FindId(guid);
// Using Subobject Material info
foreach (Rhino.Geometry.ComponentIndex ci in obj.SubobjectMaterialComponents)
{
Rhino.DocObjects.Material face_mat = obj.GetMaterial(ci);
Console.Out.WriteLine($"Face material: {face_mat.Name}");
}
// Iterating over Brep Faces
Rhino.DocObjects.BrepObject brep_obj = (Rhino.DocObjects.BrepObject)obj;
foreach (Rhino.Geometry.BrepFace face in brep_obj.BrepGeometry.Faces)
{
int index = face.MaterialChannelIndex;
Rhino.Geometry.ComponentIndex cidx = face.ComponentIndex();
Rhino.DocObjects.Material mat = brep_obj.GetMaterial(cidx);
Console.Out.WriteLine($"Face Material index {index} Material: {mat.Name}");
}
@dale enclosed you’ll find a Brep with a part with the guid used in the code that has a material assigned per object and materials assigned per face to test.