Sort Dynamo points by coordinates


#1

http://image.prntscr.com/image/1d3ebd863adf490382ab2c2c5a008929.png


Lexicographic sorting
#2
reset = IN[0]
if IN[1] != True: off = 1/0

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

from operator import itemgetter

pts0 = IN[2]

pts = map(lambda p: [p.X, p.Y, p.Z, p], pts0)

sortpts = sorted(pts, key = itemgetter(0,1,2))

OUT = map(lambda x: x[3], sortpts)

#3

@Khasan_Mamaev This should work too…

Using Design Script…


#4

Ooh, fine


#5

And if it’s not Dynamo points, but nested lists
http://image.prntscr.com/image/6c2a7674c6204c0e92c35fbad05ee2b6.png


#6

http://image.prntscr.com/image/28f6f018b6814e169ece08a19afa99ac.png


#7

But be aware that the Python script works much faster than the Dynamo script. This becomes clear when the elements are sorted by more than a thousand