Revit Elements - Group by Space, Sort groups by Level & Distance from point, Renumber

A solution to this is eluding me - perhaps I’ve bitten off more than I can chew for now. Could anyone provide me with some pointers?

What I want to achieve is to take a list of Air Terminals, group these by the space in which they reside, then sort the space groups by Level/Distance from a point. Then I plan to flatten the list so that I can renumber in a new sequential order. Phew…hope that makes sense. See a breakdown and graph below:

Proposed Method

Collect & Sort Spaces by Distance, then Level

  1. Collect all space elements that are placed in a model. Success
  2. Sort Spaces by distance from Project base Point. Success
  3. Then further sort spaces by Project Level. Success

Collect Air Terminal Elements & Group these By Space
4. Collect all Air Terminals. Success
5. Group all Air Terminals by the Space they are located within. This uses the archi-lab custom node “Elements in Space - This node will take an input of Spaces and Elements and attempt to group all elements by Room that it is located in.”. Success

Final Steps
6. Sort the list of Air Terminals (Grouped by Space), those from item 5, by a “key”. The key should be the sorted order of the Space List from item 3. FAIL???
7. Rename Air Terminals - Set mark to new value Success

Tried another simpler route, using the Rhythm node “FamilyInstance.Space” this time. Still no joy with the final result, however I have isolated this warning in my final “Sort By Key” Node:


At least one object must implement IComparable.


I think this is telling me that Space elements can’t be used as keys to sort Air Terminal elements. Does that sound correct?

…simplified the point of failure, which is illustrated in this graph

At least one object must implement IComparable.