Quirky Material Tracking Behavior

I’m sharing a behavior that took me a while to figure out. I’m not sure it should be improved, but I’ll at least post so others can see. I have a workflow for importing Rhino geometry as Direct Shapes.

Select some geometry to convert, assign it to a node (Right click, select elements)
Create generic color Materials and Material assets. e.g., CAD_255,0,0 for Red
Use these to generate geometry
Release the geometry in canvas by selecting it and choosing “Release Elements”
Select some new geometry to convert, assign it to the same node (Right click, select elements)

Outcome: The materials I assigned to the original geometry is deleted or updated. Updated if the material count is equal, deleted if the material count goes down. If I go from creating a red and green shape to creating just an orange shape. The red becomes orange and the green is deleted.

I incorrectly expected that by releasing the elements, I would also release the materials I associated with those elements. I see now that I need to build a Release Element node that releases both the Direct Shapes and the Materials. This behavior occurs even if I have the tracking mode to “Update”. I’m using a Create Material node, but most the materials I’m working with have already been created.

So, for example if I had been using “Red” for a while in the project and my script sees that Red material and uses it to create a Direct Shape, it will also happily delete that "Red " material on the next run even though I thought I’d released the elements via the Revit ribbon.

The improvement I came here to share, which I’m no longer confident of would be:

Track the use of materials in the creation of objects. Associate the material tracking with any objects created with their use. When user releases an element (or maybe all elements) associated with a tracked material, stop tracking that material.

Demo of behavior in attached file. To use, run once and then release the sphere. Move it off to the side in Revit. Back in GH, click the bool toggle. After a Revit canvas refresh, you’ll see that the old sphere updates it color.

Toggle Color Demo.gh (11.3 KB)

Hi Alexander,

If i understand your question correctly, the Material is a separate Revit Element and is tracked as such, so unpinning the DirectShape does not disassociate the Add Material creation.

Yes, exactly. Sorry for the wordiness. I didnt realize unpinning had the same effect as the toolbar button. I’ve just started RiR this week.

1 Like