MaterialTableEvent don't send event?

Hello
Is this a bug or a missing feature or an error in the code?
The event don’t sent when i add a material from Materials tab

Rhino.RhinoDoc.MaterialTableEvent += OnMaterial;
Rhino.RhinoDoc.RenderMaterialsTableEvent += OnRenderMaterial;

static void OnMaterial(object sender, Rhino.DocObjects.Tables.MaterialTableEventArgs args)
{
    if(args.EventType == Rhino.DocObjects.Tables.MaterialTableEventType.Added || 
        args.EventType == Rhino.DocObjects.Tables.MaterialTableEventType.Modified ||
        args.EventType == Rhino.DocObjects.Tables.MaterialTableEventType.Deleted ||
        args.EventType == Rhino.DocObjects.Tables.MaterialTableEventType.Undeleted)
    //Do something....
}

static void OnRenderMaterial(object sender, Rhino.RhinoDoc.RenderContentTableEventArgs args)
{
    if (args.EventType == Rhino.RhinoDoc.RenderContentTableEventType.Loaded || args.EventType == Rhino.RhinoDoc.RenderContentTableEventType.MaterialAssignmentChanged)
    //Do something....
}

You shouldn’t be using the MaterialTable. That is old-style materials and not working as you (probably) think.

The material table you are using in code is for mapping between objects and materials. If you have five objects in your document, and you assign them all the same material you’ll end up with five entries in the material table. Now if you have 100 objects, but no materials assigned to them, yet you have 20 materials visible in the materials panel then material table will be empty.

What you are really looking for is the RhinoDoc.RenderMaterials Property table. That doesn’t have events exposed for when materials are added, edited or deleted in that table though. I am currently not aware of a mechanism to get those from RhinoCommon and if that is published (there are obviously mechanisms, otherwise the materials wouldn’t show in the materials panel XD ).

Probably need to poke @johnc and @maxsoder about how to get events for these document changes

1 Like

Thanks @nathanletwory

The shader component update the list of materials by click
I want the same so how this component get all materials added , renamed , removed …etc ?

I’d imagine the menu gets populated by just iterating over the materials in the RenderMaterials table when the context menu for the shader component is opened.

Thanks @nathanletwory
I am using your solution here and it works perfectly

Ah, forgot about that XD.

1 Like