Create Set / Tree Structure Problem

Hello,
This should be a trivial problem, but I’m trying to solve it for the second day and finally decided to ask for help.

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.

Unfortunately, I can’t go past the first stage of sorting! I can only separate animals by species.

In the white group of my definition is what goes as expected and the red one is giving me the wrong results.

GH FILE:
CREATE SET TEST2.gh (18.4 KB)

Can somebody please show me how I can further divide my tree structure? Create set method is giving me the wrong results. I ran out of ideas how to proceed.

Hi,

This is a classic error with data trees, you are feeding a component with different structures.

There are several workarounds described in this thread

Problem with data matching.

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.

A preview of what is waiting for you :sweat_smile:

CREATE SET TEST2.gh (28.2 KB)

3 Likes

Thank you very much, it’s working! :slight_smile:
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 !

1 Like

This thing should be easier in Grasshopper 1.0 and in GH2. I hope it will be addressed by some more compact, native components.

1 Like

Recently I had this exact problem for months that I finally managed to solve.
I was trying to create sets of similar values inside different trees.
This strategy give you the chance to create sets on sets.

Creating sets on sets

I hope this help you too

create sets on sets.gh (10.8 KB)