#! python3 # Okseong pentagon stirrups C9/C11/C13 lap c=630 (수정7 -> 수정8). Based on: Sanoe coping shear bars rebuilt with lap J (drawing shapes II / III / XII / VIII), as in the Daehoji method # II (C7-C9) : lid (top bar + both legs C=660 down) + bottom (bottom bar + both legs full height up) [vertical stirrup, plane x=const] # III (C10) : left U + right U overlapping J=660 at the middle of the top and bottom edges [horizontal band, plane z=const] # XII (C12) : same as III with corner R400 # VIII(C13) : two hooked pieces overlapping J=660 in the middle of the straight run # Source: 산외교P1 G5_수정2_20261026.3dm -> 산외교P1 G5_수정4_20261026.3dm (수정3 was cancelled) 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 import Rhino.Geometry as rg from Rhino.Geometry import Point3d, PolylineCurve, Curve, Brep, PipeCapMode from c1_core import BASE, required_rc DATE_TXT = "2026-10-27" SRC = os.path.join(BASE, "검토_옥성교P1", "옥성교P1_G5_수정7_20261027.3dm") DST = os.path.join(BASE, "검토_옥성교P1", "옥성교P1_G5_수정8_20261027.3dm") OUT = r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work\c1_lap_okseong_pent.json" SPEC = {"C9": ("ring", 630.0), "C11": ("ring", 630.0), "C13": ("ring", 630.0)} res = {} def robust_pipe(curve, d, tol): for fit, atol in ((True, tol), (False, tol), (True, 0.01), (True, 0.1)): rr = Brep.CreatePipe(curve, d / 2.0, False, PipeCapMode.Flat, fit, atol, Rhino.RhinoMath.ToRadians(1.0)) if rr and len(rr) == 1 and rr[0].IsSolid: vol = rg.VolumeMassProperties.Compute(rr[0]).Volume if abs(vol / (math.pi * (d / 2.0) ** 2 * curve.GetLength()) - 1.0) <= 0.005: return rr[0] return None def fillet_poly(pts, R, tol): pc = PolylineCurve([Point3d(*p) for p in pts]) f = Curve.CreateFilletCornersCurve(pc, R, tol, Rhino.RhinoMath.ToRadians(1.0)) return f if f is not None else None def first_arc_radius(c): for i in range(c.SegmentCount): ok, arc = c.SegmentCurve(i).TryGetArc() if ok and not c.SegmentCurve(i).IsLinear(): return arc.Radius return None def pieces_ring(c, J): # closed ring whose seam is on the right vertical side: two pieces overlapping J (centred on the seam) c = c.DuplicateCurve() # drawing: the lap runs down the long vertical side starting at its top end -> move the seam to the middle of that stretch best, bl = None, 0.0 for i in range(c.SegmentCount): sg = c.SegmentCurve(i) if sg.IsLinear() and sg.GetLength() > bl: best, bl = i, sg.GetLength() sg = c.SegmentCurve(best) a0, a1 = sg.PointAtStart, sg.PointAtEnd if abs(a1.Z - a0.Z) < 0.9 * bl or bl < J + 100.0: return None top, bot = (a0, a1) if a0.Z > a1.Z else (a1, a0) seam = top + (bot - top) / bl * (J / 2.0) if not c.ChangeClosedCurveSeam(c.ClosestPoint(seam)[1]): return None L = c.GetLength() h = J / 2.0 t = lambda sv: c.LengthParameter(sv)[1] tm, tmid, tp = t(L - h), t(L / 2.0), t(h) p1 = [c.Trim(tm, c.Domain.Max), c.Trim(c.Domain.Min, tmid)] p2 = [c.Trim(tmid, c.Domain.Max), c.Trim(c.Domain.Min, tp)] out = [] for pp in (p1, p2): if any(q is None for q in pp): return None j = Curve.JoinCurves(pp, 0.01) if not j or len(j) != 1: return None out.append(j[0]) return [("좌", out[0]), ("우", out[1])] 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 breps = collections.defaultdict(list) curves = [] for o in doc.Objects.GetObjectList(st): g = o.Geometry L = lay.get(o.Attributes.LayerIndex, "") if isinstance(g, Brep) and "철근" in L: breps[o.Attributes.Name].append(o) elif isinstance(g, Curve) and "중심선" in L and o.Attributes.GetUserString("mark") in SPEC: curves.append(o) stat = collections.Counter() info = collections.defaultdict(lambda: {"len_old": [], "len_new": [], "pieces": 0}) for o in curves: a = o.Attributes m = a.GetUserString("mark") shape, J = SPEC[m] req, d = required_rc(a.GetUserString("dia")) nb = breps.get(a.Name.replace("-RC-", "-R-"), []) c = o.Geometry if len(nb) != 1 or not c.IsClosed: stat[m + "_unexpected"] += 1 continue try: pcs = pieces_ring(c, J) if pcs is None: stat[m + "_ring_none"] += 1 continue except Exception: stat[m + "_split_error"] += 1 continue if any(p[1] is None for p in pcs): stat[m + "_piece_none"] += 1 continue pipes = [] for nm, pc in pcs: pp = robust_pipe(pc, d, tol) if pp is None: break pipes.append(pp) if len(pipes) != 2: stat[m + "_pipe_fail"] += 1 continue cid, bid = o.Id, nb[0].Id ca = a.Duplicate() ba = nb[0].Attributes.Duplicate() (n1, c1), (n2, c2) = pcs ok1 = doc.Objects.Replace(cid, c1) and doc.Objects.Replace(bid, pipes[0]) if not ok1: stat[m + "_replace_failed"] += 1 continue ca2, ba2 = a.Duplicate(), nb[0].Attributes.Duplicate() for at, nm, base in ((ca2, n2, a.Name), (ba2, n2, nb[0].Attributes.Name)): at.Name = base + "-" + nm doc.Objects.AddCurve(c2, ca2) doc.Objects.AddBrep(pipes[1], ba2) for oid, nm, base in ((cid, n1, a.Name), (bid, n1, nb[0].Attributes.Name)): ro = doc.Objects.FindId(oid) at = ro.Attributes.Duplicate() at.Name = base + "-" + n1 at.SetUserString("lap_fix", "shape %s: two pieces (%s/%s) lapped J=%.0f (%s)" % (shape, n1, n2, J, DATE_TXT)) doc.Objects.ModifyAttributes(ro, at, True) i = info[m] i["pieces"] += 2 i["len_old"].append(c.GetLength()) i["len_new"].append(c1.GetLength() + c2.GetLength()) stat[m + "_done"] += 1 res["stat"] = dict(stat) res["info"] = {m: {"bars": len(v["len_old"]), "avg_len_old": round(sum(v["len_old"]) / max(1, len(v["len_old"])), 1), "avg_len_new_sum_of_pieces": round(sum(v["len_new"]) / max(1, len(v["len_new"])), 1)} for m, v in info.items()} doc.Strings.SetString("수정일", DATE_TXT) prev = doc.Strings.GetValue("수정내용") or "" doc.Strings.SetString("수정내용", (prev + " | " if prev else "") + "coping pentagon stirrups C9,C11,C13 rebuilt as two pieces lapped c=630 at the seam (right vertical side)") 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)