Merge Data Tree Branches

Hey everyone,
this might be an easy one (maybe with the PathMapper component or an Expression?) I tried whatever I knew how to operate, however I have no idea what to do, so -
I have a Data Tree with 33 Branches (each of those contains a varying amount of lines). Now I want to merge the Branches so that there are only 11. They won’t be the same size, since the amount of lines varies. I really only want it likes this:
{0}, {1}, {2} => {0}
{3}, {4}, {5} => {1}

{30}, {31}, {32} => {10}

It would need to be correct not only for this combination, so I can use it for different situations like for from 66 to 11 Branches or 120 to 6 Branches… My problem is that I cannot flatten the original Data Tree without losing the structure… Thanks in advance :slight_smile:

Hopefully, this demo will let you get the same result as you described.
Regardless of using Flatten, you can regroup your branches usingPartition List with List Length.
And Unflatten let you retrieve your original data tree structure. (12.4 KB)

1 Like

Thanks so much for taking the time :slight_smile: It works perfectly!

Hello medequ,
There is an even simpler solution with path mapper :

If you want to group paths 3 by 3, you just have to divide the path number by 3.
Since path mapper rounds the value, {0}/3=0 becomes {0}, {1}/3=0.33 becomes {0} but {2}/3=0.66 becomes {1}. That is why I added 2 to the path number to make sure {0}, {1} and {2} would be in the same group.
I hope this helps !

1 Like