Hi everyone,
i have created a small python script that takes a bunch of input curves, get’s their midpoints and then sorts these in ascending or descending order on a user chosen axis. Quite handy to figure out which is the top curve, bottom curve etc.
It works well if the selection order of the curves is linear (e.g. left to right, right to left) but if I chose curves in a random order it stops working and returns a random list again.
Could anyone please check it out? There is a attached Rhino file with curves that are spread out on the x axis and the gh file with the components in question.
Below is the python code and an image showing the setup. X=0 axis, if you connect “select from left to right” or “select from right to left” to the ghpython inObjects it will work in both directions both with Biggest first set to True and False… If you connect “random select” it does not…
Any ideas? I really do not get what is wrong with it
if objectType == 4:
#Get the midpoints of the input curves
for c in inObjects:
midPoints.append(rs.CurveMidPoint(c))
#deconstruct the midpoints and get values for the specified axis
for point in midPoints:
axisVals.append((point[axisNr]))
#Make a copy of the list
sortedVals = list(axisVals)
print(axisVals)
#sort sorts by ascending order by default
if maxFirst == True:
sortedVals.sort(reverse=True)
if maxFirst == False:
sortedVals.sort(reverse=False)
print(sortedVals)
#Find every value in the sorted list and store an index order
for val in axisVals:
indices.append(sortedVals.index(val))
print(indices)
#Resort the curves to the new order based on the indices
for i in indices:
sortedObjects.append(inObjects[i])
outObjects = sortedObjects
randomSelectionOrderNotSortable.3dm (29.4 KB) randomSelectionOrderNotSortable.gh (10.6 KB)![curvestopview|690x286]