#! python3 # read-only: hook / leg direction of hooked bars (Okseong P5, Ramp-A P3, P3-1) and where P3-1 leaves the concrete import sys, os, json, math, collections, traceback sys.path.insert(0, r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work") import Rhino import Rhino.Geometry as rg from c1_core import BASE FILES = {"okseong": (os.path.join(BASE, "검토_옥성교P1", "옥성교P1_G5_수정6_20261026.3dm"), ["P5"]), "rampa": (os.path.join(BASE, "Ramp-A교P1", "ramp-A G5_수정5_20261026.3dm"), ["P3", "P3-1"])} OUT = r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work\c1_hook_dir.json" res = {} try: for key, (p, marks) in FILES.items(): 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} concrete = [] bars = collections.defaultdict(list) for o in doc.Objects.GetObjectList(st): g = o.Geometry L = lay.get(o.Attributes.LayerIndex, "") if isinstance(g, rg.Brep) and g.IsSolid and "철근" not in L and ("기둥" in L or "코핑" in L or "기초" in L): concrete.append((L, g)) if isinstance(g, rg.Curve) and "중심선" in L and o.Attributes.GetUserString("mark") in marks: bars[o.Attributes.GetUserString("mark")].append(o) out = {} for m, lst in bars.items(): leg_down = hook_down = 0 tail_z = [] outside_where = collections.Counter() out_pts_z = [] for o in lst: c = o.Geometry s0, sN = c.SegmentCurve(0), c.SegmentCurve(c.SegmentCount - 1) legz = s0.PointAtEnd.Z - s0.PointAtStart.Z # leg runs from its free end toward the bend: positive = leg end lies below the bend if legz > 0: leg_down += 1 tz = sN.PointAtEnd.Z - sN.PointAtStart.Z tail_z.append(tz) if tz < 0: hook_down += 1 n = max(40, int(c.GetLength() / 15.0)) ts = c.DivideByCount(n, True) L = c.GetLength() for i, t in enumerate(ts): pt = c.PointAt(t) if not any(b.IsPointInside(pt, 0.01, True) for _, b in concrete): frac = i / float(len(ts)) outside_where["hook end" if frac > 0.8 else ("leg end" if frac < 0.2 else "middle")] += 1 out_pts_z.append(round(pt.Z)) out[m] = {"n": len(lst), "leg_end_below_bend": leg_down, "hook_tail_points_down": hook_down, "tail_dz_range": [round(min(tail_z), 1), round(max(tail_z), 1)], "outside_points_by_part": dict(outside_where), "outside_z_range": [min(out_pts_z), max(out_pts_z)] if out_pts_z else None} 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)