Sorting list in numeric order

Hi all,

I’m exporting data to Excel and in my first tests it all went wel.
but then I had 9 piles. Now I have 12 piles and my export list is like:
1
10
11
12
2
3

How can I sort the list that 10 comes after 9 and 20 after 19 and so on.

King regards,
Mike

Do you mean that ?

or that

1 Like

Hi @Mohammad_Nawar,

no, that’s not what I mean. I have a list of lists and in those lists are items like Pile number X- Y- and Z-coordinates.
And this set-up is okay. This is my input list for the “data” input of the “Excel.WriteToFile” node.
But…it’s not in the correct order. If I have 40 Piles in my model and want to export all 40 coordinates to Excel in this moment I get an excel sheet that start like this:
1
10
11
12
13
14
15
16
17
18
19
2
20
21
etc.

So it’s not numeric in order.
I need it to be:
1
2
3
4
5
6
7
8
9
10
11
12
etc.

I thought it would work by adding the 'List.GetItemAtIndex" node and have it get the items at the start of the list (0;)
and that worked…for pile counts under 10! but now as I try my script on a completed project to see if the scripts works like it should. I found out my pile numbering in Excel is not numeric in order.
Can that be fixed?

OH…STOP!
I didn’t notice your second screenshot!
That’s more what I need!
I’ll have a go at it!

I suspect your pilenumbering is strings? Then you may have to pad the strings so you can sort them right.

2 Likes

Hi @Mohammad_Nawar,

Sorry, that second screenshot didn’t work either.

Hi @jostein_olsen,

No, I believe it’s not a string. Hahahaha…at least that’s what I think with my limited knowledge of Dynamo. :slight_smile:
Basicly what the script is doing is to get the Pile elements from Revit and use the Survey Point as 0,0 and then combines the list (Pile number, X, Y and Z). Then I want to shuffel all in numeric order…add some headers and then export it to Excel.


(The yellow warning is not relevant)

Sorry to break your heart, Mike, but it is indeed a string, since you are extracting the Mark value of your piles. :slight_smile:
Since strings are sorted like I stated, you must either pad the “numbers” or
convert the extracted Mark value to a number using the String.ToNumber node before plugging it into the List.Create node.

2 Likes

:sweat::sweat::sweat::sweat::sweat::sweat::sweat:
I’m Never to old to learn!
Okay…than I’ll try the string.tonumber node because changing 1 into 01 is tricky.
I don’t want to add 3 zero’s (0001) for project that could have as many as 1000+ piles.

The reason for that is that I have this piece of code in another script that deals with imported coordinates from Excel given by a contractor. Those given pile coordinates are the as-built piles and that script compares them to the designed piles in my model. It get’s the date and compares the coordinets based on the pile number.

And I could get a completed script from the internet that does the same thing…but then I wouldn’t have learn a thing and the script isn’t mine! And when the script isn’t mine…it’s harder to understnad what it does.

So I’m building the script my way … with help from experts of this great forum! :slight_smile:
And I’m going to try your input Jostein! Thanks for helping.

@jostein_olsen

String.ToNumber did the trick!!
THANK YOU!!!
:+1::+1: