Reorder tree branches by internal values

Hi,

I am trying to reorganize a tree based on the value of the attributes of the objects contained in the branches.

The starting point is this: I am drawing each building volume (or group of buildings) in a different layer. The volumes are composed of “floors” that are then assigned a material. The materials can be used in any layer, so some materials are repeated in different layers (top right view).

In the file I am attaching, there are three layers that get reported in Grasshopper as three branches. I am able to then split the corresponding branches according to the materials contained in that layer, creating subbranches inside the three main branches.

However, when I try to use this information to reorganize the actual geometry the Replace Path component is not working as expected and it generates again a tree with just three branches (removing the subbranches).

I would like to know how this could be fixed. I already saw some posts similar to this (like this), but they are not working exactly in the way I need.

Any help is more than welcome. Thanks in advance.

Reorder branches by values.gh (48.7 KB)
Sample.3dm (1.5 MB)

not sure I have understood correctly what you’re after :slight_smile:

your original tree has 3 branches (1 per layer of course) and each layer has items with several materials

you want sub-branches to be added depending on the material each geometry belongs to, in such a way each sub-branch consistently indicates the very same material across the 3 original branches?

if that is the case, this might work:
[edit: the following definition produces the wrong result :slight_smile: ]


Reorder branches by values_Re.gh (25.1 KB)

if that is not the case, I should read your post again a dozen times :slight_smile:

Hi @inno,

thanks for your help, but I do not think that it is completely working the way I need, because for example in the branch {1;1} you are getting two different materials (Bolig and Næring, sorry, Norwegian language :sweat_smile:)

Let me try to explain again what I am trying to solve.

In this example I have a flat list and I reorganize the materials in a way that all the materials are organized in different branches according to their values. What I am trying to do is the same but not for flat lists but for tree structures, where each branch is representing a different building (layer) with its materials, that then get sorted out in subbranches according to their values.

In any case, thanks for your help :slightly_smiling_face:.

well… let me say first that you are right :slight_smile: and the thing I did post earlier was obviously returning wrong results

the trick to make it work “as similar as possible as it is” is to duplicate the input data tree too List Item in such a way it matches the data tree of the index input

long story short: because of the tree structure of A → then → B must become like C
in such a way the tree structure of C ≈ similar to ≈ tree structure of A

the new branching looks right to me now:

Reorder branches by values_Re_re.gh (106.1 KB)

1 Like

Thank you @inno. This is exactly what I needed! :slightly_smiling_face:

Hey, I’m running into the exact same issue as you here, and I can’t understand why the Set-Member index doesn’t behave as expected when you add a level of complexity to the tree. Any explanation for it?
I always try to avoid solutions that need to duplicate data, but I’m not sure if can do it in this case.
@Joseph_Oster I’m tagging you here because I’ve seen your past explanations on this topic and maybe you’re able to enlighten us, sorry if this is not appropriate!

In certain “special cases”, duplicating data is the easiest way to resolve data tree matching. Here is a recent example:

White group:

Can you post an example?

-Kevin

1 Like
  • Put a Trim Tree component between the Member Index component and theList Item component
  • Put an Unflatten Tree component after the List Item
    • Use input to Trim Tree component as Guide input to Unflatten Tree

Edited file posted by @inno above. Added items in yellow group and updated eleFront components.

Kind of a mess, but I wanted to leave the original components to compare results.

Reorder_without_duplicating_230608a.gh (14.0 KB)

-Kevin

Well, this is kind of embarrassing, because I’ve found a solution while ordering the script to send an example here. And is a nice one that I don’t know why I didn’t try during the hours I’ve spent dealing with this member index issue :upside_down_face:
I’m explaining the problem and the solution just in case somebody ends up here:

There are several ways to group a list of elements according to some common values (keys), using sets and member index, or replacing paths or with Categorize from Elefront. But these solutions only work with flattened lists. When trying to apply the sets=member idex logic to a list one level deeper, it doesn’t work and is dangerous because the errors appear after the second outer branch (I would love to give some explanation about why, but I don’t have it).

The solution I just found it extremely simple, and I am sorry to have bothered y’all in this thread: using the CreateSet component to the keys list and applying it to a = comparison allows me to cull the original list maintaining the tree structure. Is clean and simple and I just hope that some lost soul find this helpful.
In the script you can find the options, the problematic member index and the solution! Thank you all so much for your help and knowledge :slight_smile:


GroupingTree_byKeys.gh (392.0 KB)

missing

Your code is clear as mud to me. I admit I’m not trying very hard to understand it…

I keep this image handy and refer to it often when using Member Index:

From here:

Your method is turning your list of 3560 items into a list of 3584 items.

I think this gives the result you’re looking for.

GroupingTree_byKeys_230608a.gh (375.1 KB)

-Kevin

4 Likes

Yeah! That post is really constructive and I’ve followed it but it is only applicable to flattened lists, if you try to make it work with an actual structured list as an input, then it doesn’t work, (the red example in my image)

OMG you’re totally right @kev.r , thank you very much for pointing it, I’m going to edit my optimistic post :sweat_smile:. Your solution is perfect, thank you very much.