Sorting a list in alphabetical order

Hi,

I’ve got the following script:

import rhinoscriptsyntax as rs

dot = [ ]
dot = rs.GetObjects()

for i in range (0,len(dot)):
    a = rs.BlockInstanceInsertPoint(dot[i])
    b = rs.MoveObject(dot[i],(-a[0],-a[1],-a[2]))
    c = rs.MoveObject(b,rs.GetPoint())

I created this to faster move the below letter dots to desired locations. All of them are blocks with the same name as the letter i.e.: letter dot A is called “A” block instance etc. The problem is that the script randomly picks the letter dots, rather than in an alphabetical order. How can I sort my list or do a different work around?

Letter dots

Hi Axel

Im on my phone so not able to test.
What you can do is first sort the dot list like so

dot.sort( key = lambda d : rs.BlockInstanceName(d))

The above code us not tested so maybe incorrect
But I hope it gets you on track

-Willem

2 Likes

Why don’t you just get the block instance’s name and then match or create the dot according to the name’s first letter? That way you don’t have to worry about matching sorted or unsourced lists…

Hi Willem. Thank you so much, this worked first time :slight_smile:

Hi Helvetosaur, Thank you for your reply, but unfortunately i don’t know how i would go about doing this. The above code from Willem works, so I no need to investigate further.