#! python3 # read-only diagnosis of the 102 bars the corner method could not fix: segment structure and whether CreatePipe works on the ORIGINAL curve import os, json, math, collections, traceback, sys sys.path.insert(0, r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work") import Rhino from Rhino.Geometry import PipeCapMode, Brep from c1_core import BASE, plan_curve, required_rc TARGETS = { "ungok": (os.path.join(BASE, "철근 모델랑 운곡교P1_바이브코딩", "운곡교p1_수정6_20261026.3dm"), ["P3"]), "okseong": (os.path.join(BASE, "검토_옥성교P1", "옥성교P1_G5_수정2_20261026.3dm"), ["C9", "C13"]), "rampa": (os.path.join(BASE, "Ramp-A교P1", "ramp-A G5_수정_20261023.3dm"), ["C12"]), } OUT = r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work\c1_diag_complex.json" res = {} try: for key, (p, marks) in TARGETS.items(): doc = Rhino.RhinoDoc.OpenHeadless(p) tol = doc.ModelAbsoluteTolerance st = Rhino.DocObjects.ObjectEnumeratorSettings() st.HiddenObjects = True; st.LockedObjects = True; st.NormalObjects = True lay = {l.Index: l.FullPath for l in doc.Layers} out = {} for o in doc.Objects.GetObjectList(st): g = o.Geometry if not (isinstance(g, Rhino.Geometry.PolyCurve) and "중심선" in lay.get(o.Attributes.LayerIndex, "")): continue a = o.Attributes m = a.GetUserString("mark") if m not in marks: continue dia = a.GetUserString("dia") req, d = required_rc(dia) pc, info = plan_curve(g, dia) if info["status"] == "unchanged": continue rec = out.setdefault(m, {"bars": 0, "plan_status": collections.Counter(), "orig_pipe_ok": 0, "orig_pipe_fail": 0, "new_pipe_ok": 0, "new_pipe_fail": 0, "sample": None}) rec["bars"] += 1 rec["plan_status"][info["status"]] += 1 r0 = Brep.CreatePipe(g, d / 2.0, False, PipeCapMode.Flat, True, tol, Rhino.RhinoMath.ToRadians(1.0)) if r0 and len(r0) == 1 and r0[0].IsSolid: rec["orig_pipe_ok"] += 1 else: rec["orig_pipe_fail"] += 1 if pc is not None: r1 = Brep.CreatePipe(pc, d / 2.0, False, PipeCapMode.Flat, True, tol, Rhino.RhinoMath.ToRadians(1.0)) if r1 and len(r1) == 1 and r1[0].IsSolid: rec["new_pipe_ok"] += 1 else: rec["new_pipe_fail"] += 1 if rec["sample"] is None or (rec["orig_pipe_fail"] == 1 and rec["sample"].get("flag") != "fail"): segs = [] for i in range(g.SegmentCount): s = g.SegmentCurve(i) ok, arc = s.TryGetArc() segs.append([type(s).__name__, round(s.GetLength(), 2), round(arc.Radius, 2) if ok and not s.IsLinear() else None, round(math.degrees(arc.Angle), 2) if ok and not s.IsLinear() else None]) rec["sample"] = {"name": a.Name, "flag": "fail" if rec["orig_pipe_fail"] else "ok", "valid": g.IsValid, "segs": segs} for m in out.values(): m["plan_status"] = dict(m["plan_status"]) res[key] = out doc.Dispose() except Exception: res["error"] = traceback.format_exc() res["done"] = True json.dump(res, open(OUT, "w", encoding="utf-8"), ensure_ascii=False, indent=1)