Hi everyone,
I’m trying to select every other curve and change them to green through python but it turned out the curves are not selected in order. I was assuming it starts from the left to right. If someone knows how to sort this out, please let me know. Many thanks.
Linlin
I think you will have to sort the curves yourself.
Python has a function to help:
import rhinoscriptsyntax as rs
# function that returns the X dimension of the mid of the curve
def key_function(curv_guid):
centroid = rs.CurveMidPoint(curv_guid)
x = centroid.X
return x
def Series(objects):
List = []
count = len(objects)/2
for i in range(len(objects)):
# I changed this to the mid point since I didn't have closed curves
# centroid = rs.CurveAreaCentroid(objects[i])
centroid = rs.CurveMidPoint(objects[i])
centroidPt = rs.AddPoint(centroid)
rs.AddTextDot(i,centroidPt)
if i % 2 == 0:
List.append(objects[i])
rs.ObjectColor(objects[i],(0,200,88))
return List
crvs = rs.GetObjects()
# The sorted() function of python can take a key to sort by:
# https://docs.python.org/2/howto/sorting.html#key-functions
# The key_function above returns the mid point X dimension,
# so the objects in crvs will be sorted by their X dimension.
sorted_list = sorted(crvs, key=key_function)
# Run your function on the sorted_list
Series(sorted_list)
Modify the key function to sort based on any attribute of the curves. I used X coordinate of the midpoint: