import sys, re, json sys.path.insert(0, 'pylib') import ezdxf f = sys.argv[1] d = ezdxf.readfile(f) m = d.modelspace() rows = [] FONT = re.compile(r'\\f[^;]*;') for e in m: if e.dxftype() == 'MTEXT': t = e.text t = FONT.sub('', t).replace('{', '').replace('}', '').replace('\\P', ' / ') rows.append((round(e.dxf.insert.x), round(e.dxf.insert.y), e.dxf.layer, t.strip(), round(e.dxf.char_height, 1))) elif e.dxftype() == 'TEXT': rows.append((round(e.dxf.insert.x), round(e.dxf.insert.y), e.dxf.layer, e.dxf.text, round(e.dxf.height, 1))) json.dump(rows, open(sys.argv[2], 'w', encoding='utf-8'), ensure_ascii=False) print(len(rows)) ex = [r for r in rows if 'H32' in r[3]][:3] print(ex) print(rows[:15])