Complicated element list sorting - Need help from the dynamo gurus!

Good Evening All,

Without having access to Revit/Dynamo at the moment i’ll try and ask my question with Microsoft excel as an aid…

See table below.


This is a summary of what i’m aiming for.

  1. Within dynamo i have a list of elements that i have ordered already, this is represented by the first column in the table above.

  2. Column 2 indicates whether or not the elements in column 1 are nested within a seperate family.
    If not then the cell is blank. If so then the cell contains a reference to the parent family name.

As shown in the third column. I’m trying to re-order the original list by using the following workflow.

Starting with the first element as per the ordered list in column 1…

Step 1: Has the element already been given a new sequence reference?

If yes: Skip
If no: Move to Step 2

Step 2: Is the element nested in another family?

If yes: Add this element to the new sequence and carry on the sequence will all other elements of that parent family (Family A, Family B etc) until all elements in that parent family have been sequenced, then move to the next element in the original list.

If no: Add this element to the new sequence, then move to the next element in the original list.

Rinse and repeat.

The workflow is fairly hard to put into words so as soon as i have access to revit / dynamo i shall provide a screenshot of my actual dynamo workflow.

Many thanks for any help in the mean time.

@luckysurfcs Please show what you have done so far and where you got stuck. Also providing your dyn and rvt file would help understand the issue


Edit: So based on a combination of sub family and the order that the family lands in, I think you want this?

Which you can get like this?


ComplexSorting.dyn (24.5 KB)

Hope that helps,


1 Like

Don’t be afraid to manipulate your data so that you have more control over it.

1 Like

Hi Nick, that’s awesome! Hopefully the OP approves :slight_smile:

Good Afternoon Mark!

Many thanks for your aid with this.
I spent hours last night trying to figure this out via excel (since i had no access to dynamo) and didn’t manage to come up with an efficient solution.

I have just tried your .dyn workflow and it work exactly as hoped for if the list of Family A, Family B etc. is sequential (as it was in the 2nd column of my original table). However, i’ve realised that in most cases the ‘second column’ list may go back and fourth between different family references / blank cells.

To try and explain this visually, please see sketch below:

Some more background information that will likely help understand what i’m trying to do.

This workflow is part of a bigger workflow that i’m trying to produce which will number concrete piles in an order.
I have first gathered the X / Y coordinates of each pile element within the view and then i have ordered the entire list of elements so that the first element is the pile at the top left of the view and the last element is the pile at the bottom right of the view.

Therefore, at that stage i could easily number from 1 to X, from top left to bottom right. However, the complexity comes from the piles that are nested within a parent family (a pilecap family).

I general workflow i’m trying to achieve is that they are numbered from top left to bottom right BUT as soon as it notes a pile that is nested in another family it will first number all piles in that parent family before carrying on as per the general X/Y order.

I shall no doubt make a couple of edits to this post when i read it back, its quite hard to explain.
Maybe another sketch later on :slight_smile:

Again, many thanks for your prompt response.
You are leaps and bounds ahead of me with dynamo.

Edit: I have attached a modified version of your dyn indicated the order of Family A, Family B etc as per the sketch above. Just to highlight that the end order isn’t quite there when the Family references aren’t sequential.ComplexSorting2.dyn (24.5 KB)




Try Nick’s it’s much smarter than mine and I think it does what you want?.. :smiley:



Hello Nick!

Many thanks for your input also, it’s nice to see how workflows like that can be significantly reduced!
I hadn’t seen your response before i started drafting up my reply to Mark.

I shall try your workflow ASAP though possibly i’ll still face the same issue as mentioned in my reply to mark?

Thanks again to both of you.

I’ll be trying to find some time today/tonight/tomorrow at the latest to try and develop this a little further though i usually end up with 300 nodes that could be written in a single code block :smiley:


I’m not sure what the new issue is. It seems to be the same issue you’re trying to solve in your first post.
I still get the correct order with your new example:

Maybe another explanation will help.

1 Like

Hello Nick!

I’ve yet to re-produce your workflow to try your method but as your workflow achieves the “required sequence” shown on my sketch… i believe you’ve nailed it!!

Very exciting stuff!

For now i shall mark this as the solution based on the results shown in ‘post 8’ as i’m not sure when i’ll have the time get my head into it.

Thank you very much!