In the Revit API, I'm trying to get the longest and the shortest edge of a room boundary. (room is a rectangle)
For now, I have a list of 4 bounding edges of a room.(rb_curves) These are curves. I'm trying to sort this list by the length of each curve.
sorted_rb_curves = sorted(rb_curves, key=?)
I'm wondering what I can assign to the 'key' in order to sort.
Your help would be much appreciated!
An easy way to sort lists based on object attributes is using lambda. In your case it would be:
rb_curves.sort(key=lambda x: x.Length)
where Length
is the attribute you are sorting by. Note this modifies your original list (as opposed to creating a new sorted list)
This would mean rb_curves[0]
is the shortest Boundary, rb_curves[-1]
is the longest.