"""Ramp-A P1 column rebar reading (G2: P1 main, P2 hoops, P3 ties) from D2 -> 판독/g2_values.json. D2 front view: column CL x 12741.4; shaft top (EL 45.452) at y -700829.1, coping bottom (EL 57.452) at y -692829.1; the view is broken between y -696879.1 and -696779.1 (4,000 hidden): EL = 45452 + (y + 700829.1) [+ 4000 above]. Left dimension chains (ticks at x 8216 '띠철근외측' and x 7716 '크로스타이') give the hoop / tie zones. Section C-C (centre 1045.1, -698159.3): main bars = INSERT symbols on r 875. """ import json import math from collections import defaultdict from pathlib import Path from dxftools import entities el = lambda y: round(45452 + (y + 700829.1) + (4000 if y > -696829 else 0), 1) out = {} ticks = defaultdict(set) for e in entities("D2", 6800, -706000, 9200, -688500): if e.dxftype() == "INSERT": ticks[round(e.dxf.insert.x)].add(round(e.dxf.insert.y, 1)) out["chain_hoop_EL"] = [el(y) for y in sorted(ticks[8216])] out["chain_tie_EL"] = [el(y) for y in sorted(ticks[7716])] # main bars in the front view (verticals of the column group) v = [e for e in entities("D2", 11800, -703000, 13700, -690500, "CS-RBAR-MAJR") if e.dxftype() == "LINE" and abs(e.dxf.start.x - e.dxf.end.x) < 0.5 and abs(e.dxf.start.y - e.dxf.end.y) > 3000] out["main_front"] = {"x_min_rel": round(min(e.dxf.start.x for e in v) - 12741.4, 1), "x_max_rel": round(max(e.dxf.start.x for e in v) - 12741.4, 1), "bottom_EL": el(min(min(e.dxf.start.y, e.dxf.end.y) for e in v)), "top_EL": el(max(max(e.dxf.start.y, e.dxf.end.y) for e in v))} # hoops drawn (front, EREC) and side view hoops / ties hy = sorted({round(e.dxf.start.y, 1) for e in entities("D2", 11000, -703000, 14500, -690900, "CS-RBAR-EREC") if e.dxftype() == "LINE" and abs(e.dxf.start.y - e.dxf.end.y) < 0.5 and abs(e.dxf.start.x - e.dxf.end.x) > 1500}) out["hoops_front_drawn"] = {"count": len(hy), "first_EL": el(hy[0]), "last_EL": el(hy[-1])} # section C-C main bars cx, cy = 1045.1, -698159.3 angs = sorted(round(math.degrees(math.atan2(e.dxf.insert.y - cy, e.dxf.insert.x - cx)) % 360, 3) for e in entities("D2", -500, -700000, 2600, -696300) if e.dxftype() == "INSERT" and abs(math.hypot(e.dxf.insert.x - cx, e.dxf.insert.y - cy) - 875) < 3) out["main_section"] = {"count": len(angs), "radius": 875.0, "first_deg": angs[0], "step_deg": round(angs[1] - angs[0], 3)} ties = [e for e in entities("D2", -1500, -698500, 4500, -692000, "CS-RBAR") if e.dxftype() == "LINE"] out["ties_section"] = [{"handle": e.dxf.handle, "len": round(e.dxf.start.distance(e.dxf.end), 1), "dir": "Y" if abs(e.dxf.start.x - e.dxf.end.x) < 0.5 else "X"} for e in ties] p = Path(__file__).resolve().parent / "판독" / "g2_values.json" p.write_text(json.dumps(out, ensure_ascii=False, indent=1), encoding="utf-8") print(json.dumps(out, ensure_ascii=False))