Files
CMPlanning/scripts/extract_pattern_stations.py
T
Claude c9de6f0ef3 feat: scan pattern drawings for station ranges and pattern names (Task 5)
No station range is written next to pattern names in 03-003..008; the pattern
names appear only in file names. 04-006..008 name WL/RP zones at the portals
without stations. Pattern-to-station mapping is left open, not inferred.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A5Cun3RHQKna9qxE6ybZ4A
2026-10-21 02:48:54 +00:00

29 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Task 5: support-pattern (지보패턴) station ranges from drawings 03-003..008.
Collects every TEXT that names a station (STA. / N+mmm / N+mmm.mm) and every
pattern name (NP-...) with its layer and position, without interpreting ranges."""
import glob
import os
import re
import sys
import ezdxf
RAG = sys.argv[1]
pat_re = re.compile(r"NP-\d[A-Z0-9-]*|WL-\d")
sta_re = re.compile(r"(STA\.?\s*)?\d{1,2}\+\d{2,3}(\.\d{2})?")
files = sorted(glob.glob(os.path.join(RAG, "03_본선터널굴착", "C0060303-00[3-8]*.dxf")))
for f in files:
msp = ezdxf.readfile(f).modelspace()
stas, pats = [], set()
for e in msp.query("TEXT MTEXT"):
s = e.dxf.text if e.dxftype() == "TEXT" else e.plain_text()
for m in sta_re.finditer(s):
stas.append((round(e.dxf.insert.x), round(e.dxf.insert.y), m.group(0).strip()))
for m in pat_re.finditer(s):
pats.add(m.group(0))
print(os.path.basename(f)[:28], "| patterns:", sorted(pats))
for x, y, t in sorted(stas, key=lambda r: (r[0], r[1]))[:12]:
print(f" ({x},{y}) {t}")
print(f" station-like texts: {len(stas)}")