#! python3 # try pipe-building variants on the ORIGINAL curve of one failing bar per mark (read-only) import os, json, math, itertools, traceback, sys sys.path.insert(0, r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work") import Rhino from Rhino.Geometry import PipeCapMode, Brep, NurbsCurve, Curve from c1_core import BASE T = { "okseong_C13": (os.path.join(BASE, "검토_옥성교P1", "옥성교P1_G5_수정2_20261026.3dm"), "C13", 25), "okseong_C9": (os.path.join(BASE, "검토_옥성교P1", "옥성교P1_G5_수정2_20261026.3dm"), "C9", 25), "rampa_C12": (os.path.join(BASE, "Ramp-A교P1", "ramp-A G5_수정_20261023.3dm"), "C12", 19), } OUT = r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work\c1_pipe_try.json" res = {} try: for key, (p, mark, d) in T.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} bad = None for o in doc.Objects.GetObjectList(st): g = o.Geometry a = o.Attributes if isinstance(g, Rhino.Geometry.PolyCurve) and "중심선" in lay.get(a.LayerIndex, "") and a.GetUserString("mark") == mark and a.Name.endswith("L"): r0 = Brep.CreatePipe(g, d / 2.0, False, PipeCapMode.Flat, True, tol, Rhino.RhinoMath.ToRadians(1.0)) if not (r0 and len(r0) == 1 and r0[0].IsSolid): bad = o break if bad is None: res[key] = "no failing bar found" continue g = bad.Geometry r = {"name": bad.Attributes.Name, "length": round(g.GetLength(), 1), "planar": g.IsPlanar(), "variants": {}} for blend, cap, fit, atol, angtol in itertools.product([False, True], [PipeCapMode.Flat, PipeCapMode.Round], [True, False], [tol, 0.01, 0.1], [1.0, 5.0]): try: rr = Brep.CreatePipe(g, d / 2.0, blend, cap, fit, atol, Rhino.RhinoMath.ToRadians(angtol)) ok = bool(rr) and len(rr) >= 1 solid = ok and all(b.IsSolid for b in rr) r["variants"]["blend=%s cap=%s fit=%s atol=%s ang=%s" % (blend, str(cap), fit, atol, angtol)] = {"n": len(rr) if rr else 0, "solid": solid} except Exception as e: r["variants"]["blend=%s cap=%s fit=%s atol=%s ang=%s" % (blend, str(cap), fit, atol, angtol)] = "ERR " + str(e)[:60] # sweep alternative: rebuilt NURBS try: nc = g.ToNurbsCurve() rr = Brep.CreatePipe(nc, d / 2.0, False, PipeCapMode.Flat, True, tol, Rhino.RhinoMath.ToRadians(1.0)) r["nurbs_pipe"] = {"n": len(rr) if rr else 0, "solid": bool(rr) and all(b.IsSolid for b in rr)} except Exception as e: r["nurbs_pipe"] = "ERR " + str(e)[:60] # points of the polycurve to see planarity of the pieces r["turn_planes"] = [] for i in range(g.SegmentCount): s = g.SegmentCurve(i) ok2, arc = s.TryGetArc() if ok2 and not s.IsLinear(): n = arc.Plane.Normal r["turn_planes"].append([round(n.X, 3), round(n.Y, 3), round(n.Z, 3), round(math.degrees(arc.Angle), 2)]) res[key] = r 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)