Add one branch within a tree to another branch in the same tree

I want to add the items in a branch inside a tree to the branch next to it. In other words Id like to combine two specific branches inside a tree.

So I have 3 list of curves in a tree and i partitioned them by 2, so that I can region union them in groups, since the number of the curves in each list might not be even or the curves are not next to eachother necessarily, some curves fail to be combined, therefore, I would like to give those single curves to the group of curves next to them and basically the branch after or before them. Does anyone know how? (13.2 KB)

Like so?
Although I guess hardcoding branch 6 into branch 5 isn’t always going to be your case, this might give you a clue going forward (12.9 KB)

@jopsa2 Thank you for your reply, yes I want it to work with the whole tree and any tree that is given to it later, but I guess for that I need to come up with a solution where I can get the branch and under some conditions add it to either the branch before after, right?

Exactly, and that depends on whatever you want your algorithm to do - is it always the last item? Is it multiple branches? Always at the end of the row of rectangles?

yes! and now I want to add a condition that whenever I have a branch with the length of one I have to replace it, to do so I only was able to dispatch those branches so far but not exactly sure how to make the script recognize that it should either be added to the branch before or after yet, do you have any solution on that?

got it - and you always want it to merge with the previous branch? ie. subtract 1 from the branch?

Let me know if this does it (I haven’t tested it on inputs other than the one you provided) (16.9 KB)

1 Like

@jopsa2 Thank you so much! this did the job!

1 Like