#!/usr/bin/env python3 """Compare two plan sheets layer-by-layer and list elevation-like numeric texts (decimal values in 0..1000) per layer, to locate ground levels (지반고). Read-only on the source DXF.""" import collections import re import sys import ezdxf num = re.compile(r"^-?\d{1,4}\.\d{1,3}$") def scan(path): msp = ezdxf.readfile(path).modelspace() layers = collections.Counter(e.dxf.layer for e in msp) el = collections.defaultdict(list) for e in msp.query("TEXT"): s = e.dxf.text.strip() if num.match(s) and 0 <= float(s) <= 1000: el[e.dxf.layer].append((round(e.dxf.insert.x, 1), round(e.dxf.insert.y, 1), s)) return layers, el la, ea = scan(sys.argv[1]) lb, eb = scan(sys.argv[2]) print("layers only in 001:", sorted(set(la) - set(lb))) print("layers only in 002:", sorted(set(lb) - set(la))) for lay in sorted(set(la) | set(lb)): if la[lay] != lb[lay]: print(f" count diff {lay}: 001={la[lay]} 002={lb[lay]}") print("== elevation-like numeric texts (layer: n, sample)") for name, el in (("001", ea), ("002", eb)): for lay, items in sorted(el.items(), key=lambda kv: -len(kv[1])): print(f" {name} {lay}: n={len(items)} sample={sorted(items)[:6]}")