#! python3 # scan bend radii of centerline curves in 4 review models (read-only, headless) import json, math, collections, traceback, os import Rhino BASE = r"D:\★Pier 자료\프로그램\Pier_T\검토파일" MODELS = { "ungok": os.path.join(BASE, "철근 모델랑 운곡교P1_바이브코딩", "운곡교p1.3dm"), "sanoe": os.path.join(BASE, "검토_산외교P1", "산외교P1 G5.3dm"), "okseong": os.path.join(BASE, "검토_옥성교P1", "옥성교P1_G5.3dm"), "rampa": os.path.join(BASE, "Ramp-A교P1", "ramp-A G5.3dm"), } OUT = r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work\c1_scan.json" res = {} try: for key, path in MODELS.items(): doc = Rhino.RhinoDoc.OpenHeadless(path) if doc is None: res[key] = {"error": "cannot open", "exists": os.path.exists(path), "path": path} continue st = Rhino.DocObjects.ObjectEnumeratorSettings() st.HiddenObjects = True st.LockedObjects = True st.NormalObjects = True lay = {l.Index: l.FullPath for l in doc.Layers} breps = {} curves = [] for o in doc.Objects.GetObjectList(st): g = o.Geometry n = o.Attributes.Name L = lay.get(o.Attributes.LayerIndex, "?") if isinstance(g, Rhino.Geometry.Brep) and "철근" in L: breps[n] = o elif isinstance(g, Rhino.Geometry.Curve) and "중심선" in L: curves.append(o) marks = collections.OrderedDict() segtypes = collections.Counter() for o in curves: c = o.Geometry a = o.Attributes mark = a.GetUserString("mark") dia = a.GetUserString("dia") arcs = [] if isinstance(c, Rhino.Geometry.PolyCurve): for i in range(c.SegmentCount): s = c.SegmentCurve(i) segtypes[type(s).__name__] += 1 ok, arc = s.TryGetArc() if ok and not s.IsLinear(): arcs.append([round(arc.Radius, 3), round(math.degrees(arc.Angle), 2)]) else: segtypes[type(c).__name__] += 1 ok, arc = c.TryGetArc() if ok: arcs.append([round(arc.Radius, 3), round(math.degrees(arc.Angle), 2)]) k = (mark, dia) m = marks.setdefault(k, {"n": 0, "arcs": collections.Counter(), "len": 0.0, "sample": a.Name, "obj": c, "layer": lay.get(a.LayerIndex)}) m["n"] += 1 m["len"] += c.GetLength() for r in arcs: m["arcs"][str(r)] += 1 out_marks = [] for k, m in marks.items(): nm = m["sample"] b = breps.get(nm.replace("-RC-", "-R-")) pd = None if b is not None and m["obj"].GetLength() > 0: vp = Rhino.Geometry.VolumeMassProperties.Compute(b.Geometry) if vp is not None: pd = round(2 * math.sqrt(vp.Volume / m["obj"].GetLength() / math.pi), 3) out_marks.append({"mark": k[0], "dia": k[1], "n": m["n"], "len": round(m["len"], 1), "sample": nm, "layer": m["layer"], "pipe_d_est": pd, "arcs": dict(m["arcs"])}) res[key] = {"path": path, "objects": doc.Objects.Count, "curves": len(curves), "breps": len(breps), "segtypes": dict(segtypes), "marks": out_marks} doc.Dispose() except Exception: res["error"] = traceback.format_exc() json.dump(res, open(OUT, "w", encoding="utf-8"), ensure_ascii=False, indent=1)