Files
Pier_v1/Code/교각모델링/convert_dwg.py
T
ahnyongjooandClaude Sonnet 5.5 964a841de1 chore(rebar): Pier_T_rebar 작업 폴더 초기 구성 및 외부 의존 파일 통합
- Code\rebar_pipeline, review_pipeline, pier-program을 정션에서 실제 폴더로 전환
- Code\rhino_mcp 및 CLAUDE_rhino배경.md 추가, .mcp.json은 PYTHONPATH로 새 위치 사용
- pier-program 내부 .git 제거(이력은 backup\pier-program_20261028.bundle에 보관)
- worktree 가이드 반영(CLAUDE.local.md, HANDOFF.md)
- D:\Rhino-MCP 경로 참조를 새 위치로 치환

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 11:20:18 +09:00

63 lines
2.4 KiB
Python

"""Stage 1: convert source DWG drawings to DXF with ODA File Converter.
Mirrors the audit record of the box project's dwg_conversion.py
(source/output SHA-256, entity count, drawing_verified=False).
RAG sources are read only; existing DXF outputs are never overwritten.
"""
import hashlib
import json
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
import ezdxf
ROOT = Path(__file__).resolve().parents[2]
SOURCE_DIR = ROOT / "RAG"
OUT_DIR = Path(__file__).resolve().parent / "입력DXF"
ODA = Path(r"C:\Program Files\ODA\ODAFileConverter 27.1.0\ODAFileConverter.exe")
PATTERN = "C0050205-02*-운곡교 교각도*.dwg"
def sha256(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def main():
sources = sorted(SOURCE_DIR.glob(PATTERN))
if len(sources) != 3:
sys.exit(f"expected 3 source DWG, found {len(sources)}")
OUT_DIR.mkdir(exist_ok=True)
audit = []
with tempfile.TemporaryDirectory() as tmp:
tmp_in, tmp_out = Path(tmp, "in"), Path(tmp, "out")
tmp_in.mkdir(), tmp_out.mkdir()
# Copy so the converter never touches RAG originals.
for src in sources:
shutil.copy2(src, tmp_in / src.name)
subprocess.run([str(ODA), str(tmp_in), str(tmp_out), "ACAD2018", "DXF", "0", "1", "*.DWG"],
check=True, timeout=600)
for src in sources:
produced = tmp_out / (src.stem + ".dxf")
target = OUT_DIR / produced.name
if not produced.is_file():
sys.exit(f"conversion failed: {src.name}")
if target.exists():
sys.exit(f"existing DXF must not be overwritten: {target.name}")
shutil.copy2(produced, target)
doc = ezdxf.readfile(target)
audit.append(dict(source=str(src.relative_to(ROOT)), engine="ODA File Converter 27.1.0",
source_sha256=sha256(src), output=str(target.relative_to(ROOT)),
output_sha256=sha256(target), dxf_version=doc.dxfversion,
modelspace_entity_count=len(doc.modelspace()),
layer_count=len(doc.layers), drawing_verified=False))
(OUT_DIR / "conversion_audit.json").write_text(json.dumps(audit, ensure_ascii=False, indent=2),
encoding="utf-8")
print(json.dumps(audit, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()