Hello everyone,
I’m trying to sort some objects according to the distance between them (ADBT). I am working on a definition and there is a problem that I face. Whenever I put some planar closed curves into a grasshopper curve component they come in their random order. Of course if I select them in the order that I want, the list appears in the order I want to have but this is too much work when you work with too many curves. I want to create a workflow to put them in line ADBT.
NeoArchaic has this beautiful component for sorting points ADBT here. It works fine for points but when sorting the points are not the goal but just a tool to sort other objects, I don’t know how the use the sorted points information to sort other objects accordingly (if it’s possible).
The method that I thought about this to;
- When putting the objects into the GH component, first select the object that I want to it to be the first item in the list and then rectangle-drag select all the others (This makes sure that the starting point is the one that I want the sequence to start from)
- Find the center points of objects (area centroids if curves or surfaces or volume centroids if polysurfaces, breps or meshes)
- Create the copy of the centroids list.
- Starting a for loop to get the distances between the first point and all the other points.
- Do this for all points until all points are used.
- Merge the distances list with the object list in tuple groups as this [(distance[0], obj[0]), (distance[1], obj[1]), …]
- Sort this new list to get the tuples sorted.
- Exctract the 2nd items in the tuples to form a new list, thus getting the objects sorted.
I love the GH Sort List component and it works awesome. I tried to do want I want to achieve here using that as well. The thing that I couldn’t get right was the necessity to loop. I have to extract the evaluated points from the list and re-evaluate (a shift list and cull index would do it, but again since IDK how many times I’ll have to do it, I have to use some kind of loop action…)
I know it is an old subject but I couldn’t seem to find what I was looking for so I decided to post here.
This is the ghpython code (where x gets the objects (in this case some curves) and y gets the centroids) by which I tried to realize my ideas:
import rhinoscriptsyntax as rs
import Rhino as rh
crvs = x
pts = y
pts_dup = list(pts)
distances = []
for i in range(1, len(pts_dup)-1):
first = rs.coerce3dpoint(pts_dup[:i])
check = rs.coerce3dpoint(pts_dup[1:len(pts_dup)])
gaps = rs.Distance(first, check)
gaps.sort()
distances.append(gaps[0])
pts_dup.pop()
As the interpreter gave an error on the line where it reads;
“gaps = rs.Distance(first, check)”
I stopped writing the code because I couldn’t solve the error.
"Runtime error (ValueErrorException): Could not convert None to a Point3d
Traceback:
line 655, in coerce3dpoint, “C:\Users\Erdem\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\utility.py”
line 365, in Distance, “C:\Users\Erdem\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\utility.py”
line 24, in script"
I’m open to new ideas, maybe I am completely off from what I’m trying to achieve. I’m looking forward to some answers… Thanks for reading such a long post…