Inputing lines in GH, and sorting them in order

Hi All!

I’m trying to figure out an efficient way to input a set of lines in GH, and then sort them in order.

I have uploaded two images to demonstrate the sorting structure I am trying to achieve. In essence, even though there is branching lines, I’d like to be able to navigate the lines in some known order.

One way I think I can approach this is by using an origin point to the bottom left of the lines to find the starting line. The I could loop through the list of lines to see if they share any of the start or end points from the starting line, then if so, add that next and repeat. I would also like to be able to do this if some of the networks are open, or closed (like the two uploaded images).

Any input would be greatly appreciated.

Thanks!

what’s determining 7 vs 8? (or 8 vs 9 in the second image)

or, 3 vs 4?

Hi Jeff. Not sure, but I was thinking if it was farthest away from the origin. That probably isn’t the most sustainable though.

I made this a while ago using Python. It doesn’t exactly match the order you described, but it does create a “known” order, so maybe it could work for you.

SortLines.gh (11.9 KB)

In the file you will see two Python components. The one that is currently connected (Sort by Location and Point list) is the closest to what you asked for, but depending on your lines, it might not always return an obvious order.

It only has a few options for sorting at the moment. Right now I just have: X, Y, Z, X-y (where X is dominant, then Y), and Y-x (where Y is dominant, then X). I also have positive and negative values for the sort direction.

The difference with the “Sort by Location and Point list” option is that it first sorts the points using one of the options mentioned above, then it uses a RhinoScript method to “Sorts list of points so they will be connected in a “reasonable” polyline order”. Rhino - RhinoScriptSyntax

It may be safer to use the “Sort Points by Location” options, since this should give more predictable results.

Edit: Updated to show correct image.

2 Likes