#! python3 # Ungok B9 (H16 shear bar): top 180-degree hook -> centre-line radius 65 mm, straight extension c = 150 mm (assumed, drawing has none). # Bottom 90-degree hook (b 96) and vertical leg (a 1995) are kept as in the drawing schedule. # Source: ..._수정3_20261023.3dm -> saved as ..._수정4_20261026.3dm (new name, originals untouched) import sys, os, json, math, collections, traceback sys.path.insert(0, r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work") import c1_core import Rhino from Rhino.Geometry import Arc, ArcCurve, PolyCurve, Point3d, Vector3d, LineCurve from c1_core import BASE, make_pipe DATE_TXT = "2026-10-26" R_HOOK = 24.0 C_EXT = 100.0 FOLDER = os.path.join(BASE, "철근 모델랑 운곡교P1_바이브코딩") SRC = os.path.join(FOLDER, "운곡교p1_수정3_20261023.3dm") DST = os.path.join(FOLDER, "운곡교p1_수정6_20261026.3dm") OUT = r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work\c1_b9_ungok.json" res = {} try: doc = Rhino.RhinoDoc.OpenHeadless(SRC) 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} res["objects_before"] = doc.Objects.Count foot = [o for o in doc.Objects.GetObjectList(st) if o.Attributes.Name == "P1-FT"][0].Geometry.GetBoundingBox(True) breps = collections.defaultdict(list) curves = [] for o in doc.Objects.GetObjectList(st): g = o.Geometry L = lay.get(o.Attributes.LayerIndex, "") if isinstance(g, Rhino.Geometry.Brep) and "철근" in L: breps[o.Attributes.Name].append(o) elif isinstance(g, Rhino.Geometry.Curve) and "중심선" in L and o.Attributes.GetUserString("mark") == "B9" and o.Attributes.GetUserString("host") == "P1-FT": curves.append(o) stat = collections.Counter() len_old = [] len_new = [] max_top = -1e12 for o in curves: a = o.Attributes c = o.Geometry nb = breps.get(a.Name.replace("-RC-", "-R-"), []) if len(nb) != 1 or not isinstance(c, PolyCurve) or c.SegmentCount != 4: stat["unexpected_shape"] += 1 continue segs = [c.SegmentCurve(i).DuplicateCurve() for i in range(4)] last = segs[3] ok, arc = last.TryGetArc() if not ok or abs(math.degrees(arc.Angle) - 180.0) > 0.5: stat["top_not_180"] += 1 continue p0 = last.PointAtStart p1o = last.PointAtEnd d = p1o - p0 d.Z = 0.0 d.Unitize() t = Vector3d(last.TangentAtStart) t.Unitize() p1 = p0 + d * (2.0 * R_HOOK) new_arc = Arc(p0, t, p1) if not new_arc.IsValid: stat["arc_invalid"] += 1 continue p2 = p1 + (-t) * C_EXT pc = PolyCurve() for s in segs[:3]: pc.Append(s) pc.Append(ArcCurve(new_arc)) pc.Append(LineCurve(p1, p2)) pipes = make_pipe(pc, 16, tol) if not pipes or len(pipes) != 1 or not pipes[0].IsSolid: stat["pipe_fail"] += 1 continue vol = Rhino.Geometry.VolumeMassProperties.Compute(pipes[0]).Volume if abs(vol / (math.pi * 64.0 * pc.GetLength()) - 1.0) > 0.002: stat["volume_off"] += 1 continue cid, bid = o.Id, nb[0].Id if not (doc.Objects.Replace(cid, pc) and doc.Objects.Replace(bid, pipes[0])): stat["replace_failed"] += 1 continue for oid in (cid, bid): ro = doc.Objects.FindId(oid) at = ro.Attributes.Duplicate() at.SetUserString("b9_hook_fix", "top 180 deg hook R%.0f (KDS 24 14 21 Table 4.5-1 minimum for H16), extension c %.0f (assumed: drawing has none), %s" % (R_HOOK, C_EXT, DATE_TXT)) doc.Objects.ModifyAttributes(ro, at, True) len_old.append(c.GetLength()) len_new.append(pc.GetLength()) bb = pipes[0].GetBoundingBox(True) max_top = max(max_top, bb.Max.Z) stat["replaced"] += 1 res["stat"] = dict(stat) if len_old: res["length_old"] = [round(min(len_old), 2), round(max(len_old), 2)] res["length_new"] = [round(min(len_new), 2), round(max(len_new), 2)] res["total_len_old_m"] = round(sum(len_old) / 1000.0, 2) res["total_len_new_m"] = round(sum(len_new) / 1000.0, 2) res["pipe_top_z_rel"] = round(max_top - foot.Min.Z, 2) res["footing_top_z_rel"] = round(foot.Max.Z - foot.Min.Z, 2) res["min_cover_above_hook"] = round(foot.Max.Z - max_top, 2) doc.Strings.SetString("수정일", DATE_TXT) prev = doc.Strings.GetValue("수정내용") or "" doc.Strings.SetString("수정내용", (prev + " | " if prev else "") + "B9 top hook R24 (KDS min for H16 23.85, rounded up like other H16 bends) + extension 100 (user 2026-10-26, replaces R65/R45 versions)") res["objects_after"] = doc.Objects.Count res["saved"] = bool(doc.WriteFile(DST, Rhino.FileIO.FileWriteOptions())) res["out"] = DST 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)