This is just an example definition to present my problem clearly.
I have 3 corresponding lists: animal, color, level
What I’m trying to achieve is to organize data in a multi-layer tree structure where the first layer is animal (dog, bird, cat), the second layer is subbranches (animals further sorted by their color) and third level is given animals in a given color at certain levels.
In other words, I would like to have a separate sub-list of e.g. brown dogs at level 01, brown dogs at level 00, black dogs at level 00, white cats at level 01, etc.
Graph showing what tree structure I try to achieve.
I used a solution with Trim Tree and Unflatten Tree, which is plugin-free.
I also added Sort Text on the sets, so that in each secondary and tertiary branch, the items are sorted in the same order. This is quite a mess !
I’ve also made a completely different approach, building the address of the branch from matching sets. This is in my option slightly better as a result, as it will get you the same branch number, for each level, whatever collection you actually have. Empty branches are skipped.
Thank you very much, it’s working!
The sad part is that I would never come up with this by myself. I think that it’s a bit challenging for an as common task like this. I guess I need to study the basics more carefully.
Don’t be sad, this is not an easy problem and having to deal with three-leveled trees is definitely not that common. Also it could be shorter with some plugins (Elefront for instance) or direct code if you are familiar with it.
The lesson is : double-triple check your tree levels when Grasshopper doesn’t work as intended !