#! python3 # read-only: geometry of Ramp-A P3-2 (H16) and the neighbouring P1-2 bars in the latest Ramp-A model import os, json, math, traceback, collections import Rhino P = r"D:\★Pier 자료\프로그램\Pier_T\검토파일\Ramp-A교P1\ramp-A G5_수정3_20261026.3dm" OUT = r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work\c1_p32_dump.json" res = {} try: doc = Rhino.RhinoDoc.OpenHeadless(P) st = Rhino.DocObjects.ObjectEnumeratorSettings() st.HiddenObjects = True; st.LockedObjects = True; st.NormalObjects = True lay = {l.Index: l.FullPath for l in doc.Layers} bars = {"P3-2": [], "P1-2": []} for o in doc.Objects.GetObjectList(st): g = o.Geometry if not (isinstance(g, Rhino.Geometry.Curve) and "중심선" in lay.get(o.Attributes.LayerIndex, "")): continue m = o.Attributes.GetUserString("mark") if m in bars: bars[m].append(o) out = {} for m, lst in bars.items(): o = lst[0] a = o.Attributes g = o.Geometry info = {"n": len(lst), "name": a.Name, "dia": a.GetUserString("dia"), "shape": a.GetUserString("shape"), "design_length": a.GetUserString("design_length"), "src": (a.GetUserString("src") or "")[:300], "len": round(g.GetLength(), 1), "segs": []} if isinstance(g, Rhino.Geometry.PolyCurve): for i in range(g.SegmentCount): s = g.SegmentCurve(i) ok, arc = s.TryGetArc() p0, p1 = s.PointAtStart, s.PointAtEnd t0 = s.TangentAtStart info["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, [round(p0.X, 1), round(p0.Y, 1), round(p0.Z, 1)], [round(p1.X, 1), round(p1.Y, 1), round(p1.Z, 1)], [round(t0.X, 3), round(t0.Y, 3), round(t0.Z, 3)]]) bb = g.GetBoundingBox(True) info["bbox"] = [round(x, 1) for x in (bb.Min.X, bb.Min.Y, bb.Min.Z, bb.Max.X, bb.Max.Y, bb.Max.Z)] pos = collections.Counter() for q in lst[:40]: b2 = q.Geometry.GetBoundingBox(True) pos[(round((b2.Min.X + b2.Max.X) / 2), round((b2.Min.Y + b2.Max.Y) / 2), round(b2.Min.Z), round(b2.Max.Z))] += 1 info["sample_positions(centre x,y,zmin,zmax)"] = [list(k) for k in list(pos)[:8]] out[m] = info res = 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)