Select an element and create a group of all other elements with same material

Does anyone have an example of creating a group by selecting an element (actually a nested family object) in a view and all others with the same material will be included? I need to group my top level family into groups by material. So as seen below if i select one of the green nested families i want it grouped with all the other green nested families. Group can have same name as material.

What i have that does nothing but produce and error.

Searched but nothing comes up.
Shared nested families yes.
This is a SolidWorks assembly exported via BIMDeX as a nested family. Each item is a family one level down from top assembly.

Don’t know how to look at errors.

run it in dynamo, not the player, then look for yellow nodes, hover over the triangle above it

a node is hidden…

use group by key

try lacing longest on the yellow node
btw, this view, does it have overrides? it does not look as if it is Revit default

You lost me on Lacing Longest.

It’s the 3d view in family editor.

Back to this tomorrow. Thanks for the help so far Marcel.

Is this what you are looking for?

Yes but I’m getting errors with your mods. Any clues as to why? I am dealing with nested families. I can only find List.Flatten not Flatten.

Flatten after ==. Look and the list I posted and the one in your graph. Yours is a list of lists and mine is a flat list. That should do it for you.

Group by key is not working because your list lengths do not match but I am not sure you need to do that for what you are doing.

Sorry I am on my phone and cannot do more right now.

Updated but still having errors

What is the Group.FromElements error? Can you create a group of nested family object? Have you tried this manually? Sorry from what I can see this should work.

Manual grouping works fine.