Face materials and headless Rhino Document

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:

document = Rhino.RhinoDoc.OpenHeadless(this_file_path)

I get the obj base material it has assigned and no face material data:

0 BrepFace Material: M_Material_ZZZ (1352) a106bd85-401d-4a8e-bcb2-66bb9c0f6b5b
1 BrepFace Material: M_Material_ZZZ (1352) a106bd85-401d-4a8e-bcb2-66bb9c0f6b5b

If I open the model and access the RhinoDoc instance with

document = Rhino.RhinoDoc.ActiveDoc

I get each face material data as expected.

0 BrepFace Material: T_Tx01 (1332) 57c9d9d1-9dc8-44b7-87b2-8e92606c911b
1 BrepFace Material: T_Tx02 (1087) f80e9001-dc6a-43c7-85e7-a565b3449481

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.

Can you comment on this?

Thanks!

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}");
}

Am I missing anything?

Hi @Iván_Pajares_Sánchez,

Can you post this?

Thanks,

– Dale

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

01_Textures.3dm (491.8 KB)

Hi @Iván_Pajares_Sánchez,

Thanks, I’ve logged the issue.

– Dale

1 Like