Pattern to divide branches in two halves

Hi,

Need help to parameterize a pattern so that the tree list always divide in two, first containing first half of the branches and second containing second half of the branches.
As I have it set up now I have to manually enter the pattern depending on the amount of points but would really like it to be automatic.
Divide tree in half.gh (12.1 KB)

Thanks for any help :slight_smile:

yes, but consider that also in your file you have 11 branches, and are assigning the first 5 to False, the next five to True, and then the 11th become the first repetition of this pattern so it’s false again (for this reason you have branches 0, 1, 2, 3, 4, 10 )

how do you want the splitting to work in a case like this where you have an odd number of branches to be split into two?

Hi, it only needs to work with even numbers. In case of an odd number it can fail

There is a split tree node, but it’s syntax is not really simple: DataTree selection rules - Grasshopper

That’s kind of the point of GH is that you can “automate” anything. There is never just one solution.

So just continuing to use all the nodes you already use, you could do something like:

It all really depends on how flexible the solution has to be. If its simple and you know the tree will always have that format and you just want to split it in 2, regardless of even or odd number of items in the tree, than something like this is fine.

Divide tree in half_auto.gh (18.8 KB)

1 Like

Thank you!
This works like a charm for what I need it to do.

Yes, I have been trying to figure out how I could use the syntax but couldn’t figure this one out.
Small steps :slight_smile:

In that case I wouldn’t let it “fail”, that is bad design. Instead you should then actively check if the number is even and put in a switch. That way you can actually know why a thing has failed. So the example you provided has 11 branches and should therefore fail?

I would do something like:

That way you actively prevent things from calculating downstream. This is better than letting it fail downstream, especially once your definition gets really big, because a fail might cause something to take a really long time or even crash downstream. This way you are just preventing any calculation downstream.

Divide tree in half_auto_even.gh (19.6 KB)

1 Like

That´s true, good practice. Thanks for making it more robust.

My bad with the initial file, it should have an even number of branches but I overlooked it.

1 Like