Attributes.MaterialIndex is -1

I’m trying to get the material properties of a material of an object… Not sure if I added the material incorrectly in Rhino or if I’m not getting it properly in code (C#).

The object(s) with the material are valid. But each object’s Attributes.MaterialIndex is -1.

Is it because the material is on the layer itself and not each object in the layer? And if so, how do I get the material?



Material index -1 means no material was assignd and therefore the default material is used. The default material is based on a plaster material.

But there is a material assigned to the layer that these objects are in…

Is it possible to get the material of the layer itself? Or do I need to do something else to make sure the objects in the layer are using the materials assigned to the layer? I’m getting the feeling that this code used to work, but perhaps with an API change there is a different way to get the material of an object that I am not using…

You will also have to check MaterialSource. If it is set to MaterialFromLayer you need to get the material from the layer with Layer.RenderMaterial

I just figured out that we were using MaterialIndex instead of RenderMaterialIndex

I have it working now, but so I can guard this code properly, what is the difference between the two, and should I be checking the type of material before using the appropriate index?

Thanks for help btw!

I believe the RenderMaterialIndex is into the RhinoDoc.RenderMaterials table. Here you get access to the RenderMaterials that are in your document. These are accessible even if they are not assigned.

RenderMaterial is what we would like plug-in developers to move to in favor of Material.

Understood. Thank you very much for your help!