Sorting points in sequence

Hi, I am fairly new to grasshopper and I am having issues sorting the points in sequence as shown in the image. Would appreciate if anyone can help me as I have been stuck and have been trying for a few days now..

Current issue:

How I need it to be:

063025-sorting help.gh (12.2 KB)

You forgot to internalise points from Rhino via the right mouse button

Hello,

I just did but nothing changed and may I ask what internalising data do for my case?

The points will be stored in Grasshopp definition if you did it, pls updated the attachment.

I think I managed to solve it with the help of an old thread and some modifications…

Thank you!

2 Likes

Bit of a hacky way to do it (relying on either side of the decimal point for sorting each axis), especially if you end up needing more structured data later, because the columns are not distinguished. I suspect it will also get confused by very small separations in Y.

Here’s another way of doing it that sorts by X first, then uses a Create Set component to identify the unique X positions and the Map output (ie. which Set value does each List Item match?) to allocate each point to a tree branch for each X value. Then we sort each branch by Y. We can flatten that tree to get a contiguous list, or keep it as is if you ever need to operate on columns.


structured:

sort by x then y.gh (11.0 KB)
EDIT: Removed a superfluous graft->flatten leftover from earlier experimentation

3 Likes

I get in that sort of troubles on a daily basis, expecially when dealing with (usually imported) drawings that were exported/produced with bad tolerance

what happens is that all the points in each row/column are supposed to share the same x/y coordinate, but in reality they might differ by cents/thousandth of units, but because of that they look like jumping here and there to different rows/columns:

what I usually do, is to take advantage of Sort Points (specifically its index output) and I sort a ghost version of those points with rounded coordinates (here you can insert the degree of precision you want by eventually introducing a multiplier where the node is, in the example I did here it’s not necessary, but it all depends on the size of the array)

you don’t touch the original points, but just Sort a ghost version of those that has perfect sharp rounded coordinates, then just retrieve their indexes and use those to really sort your original points, something like this:

or just use an expression of some sort to save components on canvas (this expression trims the number of decimals to the amount set by the slider, then rounds to that):

Sort_imprecise_points.gh (12.6 KB)

2 Likes

Thanks Tom! I would have never thought about it this way, I will definitely check back in the future for reference on this!

Wow, thanks inno. This is insightful for my learning as I will never have thought about it this way and I will definitely try it in the future and use it as some form of a reference as well. Thanks!