#! python3 # Pilot: 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_수정6_20261026.3dm") DST = os.path.join(BASE, "검토_옥성교P1", "옥성교P1_G5_수정7_20261027.3dm") OUT = r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work\c1_lap_okseong.json" SPEC = {"B1": ("IV", 1530.0), "B3": ("IV", 1530.0), "B5": ("IV", 1530.0), "B7": ("IV", 1530.0), "B2": ("IV", 1070.0), "B4": ("IV", 1070.0), "B6": ("IV", 1070.0), "B8": ("IV", 1070.0), "B11": ("IV", 560.0), "B12": ("IV", 560.0), "C1": ("IV", 1510.0), "C2": ("IV", 1510.0), "C3": ("IV", 1510.0), "C4": ("IV", 1510.0), "C5": ("IV", 1510.0), "C6": ("IV", 1510.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_II(c, C, tol): bb = c.GetBoundingBox(True) x = (bb.Min.X + bb.Max.X) / 2.0 y0, y1, zb, zt = bb.Min.Y, bb.Max.Y, bb.Min.Z, bb.Max.Z R = first_arc_radius(c) lid = fillet_poly([(x, y0, zt - C), (x, y0, zt), (x, y1, zt), (x, y1, zt - C)], R, tol) bot = fillet_poly([(x, y0, zt), (x, y0, zb), (x, y1, zb), (x, y1, zt)], R, tol) return [("뚜껑", lid), ("바닥", bot)] def pieces_band(c, J, tol): bb = c.GetBoundingBox(True) xc = (bb.Min.X + bb.Max.X) / 2.0 x0, x1, y0, y1, z = bb.Min.X, bb.Max.X, bb.Min.Y, bb.Max.Y, bb.Min.Z R = first_arc_radius(c) h = J / 2.0 left = fillet_poly([(xc + h, y1, z), (x0, y1, z), (x0, y0, z), (xc + h, y0, z)], R, tol) right = fillet_poly([(xc - h, y1, z), (x1, y1, z), (x1, y0, z), (xc - h, y0, z)], R, tol) return [("좌", left), ("우", right)] def pieces_VIII(c, J): # main straight run = longest segment; split with J overlap at its middle best, bl = None, 0.0 for i in range(c.SegmentCount): s = c.SegmentCurve(i) if s.IsLinear() and s.GetLength() > bl: best, bl = i, s.GetLength() s = c.SegmentCurve(best) p0, p1 = s.PointAtStart, s.PointAtEnd mid = (p0 + p1) / 2.0 u = p1 - p0 u.Unitize() a = mid - u * (J / 2.0) b = mid + u * (J / 2.0) ta = c.ClosestPoint(a)[1] tb = c.ClosestPoint(b)[1] first = c.Trim(c.Domain.Min, tb) # left hook ... up to b (extends J/2 past the middle) second = c.Trim(ta, c.Domain.Max) # from a (J/2 before the middle) ... right hook return [("좌", first), ("우", second)] 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 isinstance(c, rg.PolyCurve): stat[m + "_unexpected"] += 1 continue try: if shape == "II": pcs = pieces_II(c, J, tol) elif shape in ("III", "XII", "V"): pcs = pieces_band(c, J, tol) else: pcs = pieces_VIII(c, J) # IV: two L pieces overlapping J at the middle of the long straight bottom run 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 "") + "Okseong footing B1-B8,B11,B12 and coping C1-C6 rebuilt as two pieces with lap J (drawing j)") 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)