-
Notifications
You must be signed in to change notification settings - Fork 2
/
setPlanPts.py
34 lines (30 loc) · 1.03 KB
/
setPlanPts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import rhinoscriptsyntax as rs
import trkRhinoPy as trp
import scriptcontext as sc
import json
# levels = sc.sticky["lvldict"]
objs = rs.GetObjects('select objects', rs.filter.point, preselect=True)
# def objBBPtPair(obj):
# box = rs.BoundingBox(obj)
# minZ = box[0]
# maxZ = box[-2]
# mid = (box[0] + box[-2])/2
# return obj, mid, minZ, maxZ
# # rs.addpoint
def objPtPair(obj):
return obj, rs.CreatePoint(obj)
def sortByAxis(objs, fn=lambda x:x[1].X, r=False, key='level', start=1):
kv = []
kv2 = []
pairs = map(objPtPair, objs)
sortedpairs = sorted(pairs, key=fn, reverse=r)
for idx, pairs in enumerate(sortedpairs, start=start):
rs.SetUserText(pairs[0], key, str(idx))
kv.append((str(idx), pairs[1]))
kv2.append((str(idx), (pairs[1].X, pairs[1].Y, pairs[1].Z)))
planptdict = dict(kv)
planpts = dict(kv2)
rs.SetDocumentUserText("planpts", json.dumps(planpts))
sc.sticky['planpts'] = json.dumps(planpts)
sc.sticky['planptdict'] = planptdict
sortByAxis(objs)