Back to SDS/2 Parametric Scripts
def sortPoints(_ptlist, key='x'):
if key.lower() in ['x', 'y', 'z']:
_ptlist.sort(lambda a,b: cmp(getattr(a, key.lower(), 0), getattr(b, key.lower(), 0)))
return True
else: return False
def sortPoints1(_ptlist, key='x'):
if key.lower() in ['x', 'y', 'z']:
def cmpItems(a,b):
return cmp(eval('a.'+key.lower()),
eval('b.'+key.lower()))
_ptlist.sort(cmpItems)
return True
else:
return False
def test_script():
from point import
Point, PointLocate
from macrolib.PrintPtList import formatPtList
ptList
= []
while True:
p = PointLocate("Pick
point")
if p:
ptList.append(p)
else:
break
sKey
= 'Z'
if sortPoints(ptList, sKey) == True:
print formatPtList("Points List Sorted on %s
Attribute:" % (sKey), ptList)
else:
print
"Invalid attribute"
if __name__ == '__main__':
test_script()
'''Points List
Sorted on Z Attribute:
X attribute Y attribute Z attribute
============================================================
98-11 1/2 83-5 3/16 -19-0 1/4
129-3 7/8 123-2 5/8 -7-5 3/4
54-2 1/4 49-3 3/4 -5-11 5/8
65-6 3/4 63-5 1/4 -2-7 1/4
68-11 7/16 81-0 9/16 14-9 3/4
103-9 1/4 117-5 3/8 16-9
89-11 1/2 104-6 1/16 17-9 13/16
17-5 1/4 38-6 3/4 25-10 7/16
137-5 7/8 158-9 13/16 26-1 7/16
103-6 3/16 130-11 13/16 33-7 11/16
56-2 7/8 84-3 7/8 34-4 3/4
143-6 15/16 175-11 1/16 39-7 3/8
20-4 55-8 43-3 1/4
2-7 39-5 45-1 5/16
-13-6 5/16 33-6 5/16 57-7 1/2
94-7 7/16 161-8 1/4 82-1 11/16
-36-8 15/16 36-8 15/16 90-0
59-4 1/4 133-3 13/16 90-7
106-5 5/8 195-7 1/16 109-1 3/4
79-7 1/16 184-4 15/16 128-4 5/8
73-10 11/16 180-2 1/8 130-2 1/16
'''