import sys, json, re, math, collections sys.path.insert(0, 'pylib') import rhino3dm R = json.load(open('sw_texts.json', encoding='utf-8')) COLS = [("num", 97500, 98300), ("shape", 98300, 99000), ("dia", 99000, 99800), ("n", 99800, 100600), ("A", 100600, 101800), ("B", 101800, 103000), ("C", 103000, 104300), ("D", 104300, 105500), ("E", 105500, 106600), ("R", 106600, 107600), ("X1", 107600, 108300), ("X2", 108300, 108900), ("X3", 108900, 109500), ("X4", 109500, 110100), ("J", 110100, 111300), ("L", 111300, 112600), ("tot", 112600, 113700), ("unit", 113700, 114700), ("w", 114700, 115800), ("wh", 115800, 117500)] rows = collections.defaultdict(dict) for x, y, lay, t, h in R: if not lay.startswith('CS-TABL') or not (-278800 < y < -265300): continue for name, lo, hi in COLS: if lo <= x < hi: rows[round(y / 10)][name] = t.strip() break T = {} for y in sorted(rows, reverse=True): c = rows[y] if re.match(r'^[A-Z]{1,2}\d+$', c.get('num', '')): T[c['num']] = c for k, v in T.items(): print(k, v) json.dump(T, open('sw_table.json', 'w', encoding='utf-8'), ensure_ascii=False)