How to sequentially sort a bunch of points from different branches


I’m working on a g-code generator for a cnc router and I would like to sort the paths that the cnc follows in order to save time.

The points in the attached file (can also be seen in the immage above) come from the starting point of each path. As you can see they are sorted by their Z value and I would like to keep it that way. What I’m looking for is a way to sort these points sequentially (the result being their new indices like in the immage).

Desired result would be:
1st point of 1st branch is the starting point, once it sorts one branch it goes to the next one
Last point in the previous branch becomes the new starting point for the current branch and so on

I already tried the component sequential closest points and it doesn’t have the desired effect.
I don’t know programming but I am willing to learn the basics if the answer to this problem happens to be a script.
I was also thinking of trying anemone but would be overkill if the solution has to do with data tree manipulation.

Let me know if you need anything else, thank you.

sequential closest points.gh (16.0 KB)

As you mentioned it is either Anemone or coding way.
Here it is with Anemone, if i got you properly…

sequential closest points_RE.gh (15.7 KB)

Thank you, I will test it out as soon as I have some free time. Will let you know

The solution is very close to what I wanted, thank you!

A bit difficult to understand how it works but I’ll try, also curious as to why the solution differs from what I had in mind. Might have to do with rounding or how the closest point component works. Mind you the solution has only one point that is not in the order I thought it would be in so it’s not really a problem, just trying to understand the reason behind it.

This better?

sequential closest points_RE2.gh (22.4 KB)

Somehow way worse.

I did get to understand the first version you made and it does make sense. Tried replacing the first closest points component with sequential closest points and it does improve it but it still doesn’t do exactly what I expect it to do in some cases.

It’s just weird, logically the solution makes sense.

1 Like