Random indices order in Python

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.

indices order question.3dm (63.3 KB)
indices order question.py (444 Bytes)

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)
        if i % 2 == 0:
    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

Modify the key function to sort based on any attribute of the curves. I used X coordinate of the midpoint: