How to sort stations in Script in Flexrepeater

Dear All,

I have multiple stations available, I am trying to add them to a breakpoint container and perform sort based on status using flexrepeater and adding instances.

I am confused on what to add the script in Instances transform in flexrepeater. I am new to Ignition modules scripting. Any help would really be great.

Python sorting is pretty neat, but you need to supply a “key” which will be used to sort the list.

In this example case, assume that I have multiple instances which I would like sorted by the value of a property named “bayId”.

Screen Shot 2020-10-29 at 6.34.17AM

I would use Python’s sort() function for lists and I would supply a function which supplies the value I would like to use to sort the list.

# Here, the lambda will return the bayId value from each instance and use it as the value to determine the order
value.sort(key=lambda e: e.bayId)
return value

This should function the same way:

def get_bay_id(instance):
    return instance.bayId

# Note that here you only need to supply the function without values.
# The sort() function will use the supplied function and implicitly supply each instance.
value.sort(key=get_bay_id)
return value
2 Likes