Naming objects after render materials

Hi there,
I’m trying to write a Grasshopper script to rename Rhino objects based on their assigned render material.

So far, I can use Elefront to set each object’s name according to its material (e.g., Glass, Aluminum, Concrete).

I’m currently stuck on adding a sequential number suffix. The complication is that the same material can be used across multiple layers (for example, Layer 01 and Layer 05 are both Glass). In that case, I need the numbering to remain continuous across all Glass objects, rather than restarting per layer.

I considered sorting and creating sub-lists, but I am not sure how to reliably group objects using text keys (material names) and then generate per-material counters.

I’ve attached a sample .3dm and my current .gh file. Any tips would be appreciated. Thank you.

260113_Renaming system_WIP.gh (16.7 KB)

naming after rmatieral.3dm (113.8 KB)

This is probably easier with a little bit of scripting rather than wrangling data-trees or maybe I’m just being a bit dense, anyway, here is something to make your life easier

260113_Renaming system_WIP.gh (28.5 KB)

thank you! that scripting just does exactly what the whole thing should do…