I’ve been using Revit Dynamo lately to tackle a specific problem, and I’m wondering if there’s a way to sort points in some manner that would allow them to be properly connected.
Specifically, I’m looking for a function that enables the sorting of points in a specific direction (e.g., left to right or top to bottom), and then connecting these sorted points to create a line or polyline element.
I’ve experimented with various Dynamo functionalities so far, but haven’t found a solution that fully meets my expectations. Any help and ideas would be greatly appreciated!
You can sort points in pretty much any way you’d like, but the specific ‘how to’ requires understanding the logic which you’re after.
X value
Y value
Z value
Parameter along a curve
Distance from a point
Angle from other point when both points are taken as vectors.
Whatever else’s you can think of
These can also be combined as desired (i.e. grouping and sorting by angle from the X axis then distance from the center).
The hard part of this (as @pyXam pointed out) is that the reason to use any one sorting method will depend on what you’re actually after. I might guess that the actual order of points you wanted in your screenshot was [0,1,2,3,5,6,4]. If so you can try this:
Draw a circle by best fit though the point group.
Use a Curve.PointAtParameter node to find the parameter of each point on the circle.
Use a List.SortByKey node to sort the points by the parameter values.
Draw the polycurve though the sorted group.
Depending on how the circle was drawn (and so really the base points and their relationship to the global coordinate system), this could be sufficient. In other cases you might need to use an alternative method.
All of that said, I find that most of the time when we see points collected like this there is a better way to get to the data you are after (i.e. if these were extracted from floors you can use the curve loop directly).
Yes, the correct order would be [0, 1, 2, 3, 5, 6, 4]. I worked with planes fitted to points and vectors associated with them as you see on the pic. However, the List.SortByKey function does not run properly.