25 lines
1.0 KiB
Python
25 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Task 4: dump the variable table of the standard section (C0060303-001) as a
|
|
coordinate grid. Rows = cross slope (S, 편경사) per user answer 2026-10-21; the
|
|
first row = variable names. Every TEXT on the table layers is kept (no regex
|
|
filter), so that the S column and the header row can be checked."""
|
|
import csv
|
|
import sys
|
|
from collections import defaultdict
|
|
|
|
import ezdxf
|
|
|
|
SRC, OUT = sys.argv[1], sys.argv[2]
|
|
msp = ezdxf.readfile(SRC).modelspace()
|
|
cells = [(round(e.dxf.insert.x, 1), round(e.dxf.insert.y, 1), e.dxf.text.strip())
|
|
for e in msp.query("TEXT") if e.dxf.layer in ("CS-TABL-TEX1", "CS-TABL-TEX2")]
|
|
rows = defaultdict(list)
|
|
for x, y, s in cells:
|
|
rows[round(y / 50) * 50].append((x, s)) # bucket by ~50 mm
|
|
with open(OUT, "w", newline="", encoding="utf-8") as fh:
|
|
w = csv.writer(fh)
|
|
for y in sorted(rows, reverse=True):
|
|
line = [s for x, s in sorted(rows[y])]
|
|
w.writerow([y] + line)
|
|
print(f"Y{y:>7}: " + " | ".join(f"{x:.0f}:{s}" for x, s in sorted(rows[y])))
|