"""G3 stage, form "mats" (Ulsan P1, 2026-10-13): footing rebar as explicit bar groups, perimeter hoops and vertical bars, from params `footing_rebar` (centreline + pipe solid per bar). Run inside Rhino 8 via runner (globals PARAMS_PATH) after the G1 builder. z values are above the footing bottom. params footing_rebar: groups [{mark, axis "X"|"Y", z, pos [...], a, leg (signed: + up / - down / 0), lap, src}] a bar along `axis` of length a centred on the footing, at `pos` across, with end legs design length = a + 2|leg| + lap (lap only adds length) hoops {mark, half, levels [...], design_length}: closed square hoops of centreline half-width `half` verticals {mark, grid_x [...], grid_y [...], parity, z0, a, leg}: vertical bars on a checkerboard of the grid, legs of length `leg` towards +`leg_axis` ("X"|"Y") at both ends (shape I with b, SD400 catalogue) Optional (Ulsan P2, 2026-10-15; absent -> unchanged): footing.rot_deg all bars are built in the foundation's own axes and turned counter-clockwise about the pier centre hoops.half_x / half_y rectangular hoop (default: square `half`) verticals.points [[x, y], ...] explicit positions instead of the checkerboard; leg_bottom / leg_top leg lengths per end (default `leg`); design length = a + leg_bottom + leg_top """ import json import math import Rhino import Rhino.Geometry as rg import System from Rhino.DocObjects import ObjectAttributes from System.Drawing import Color P = json.load(open(PARAMS_PATH, encoding="utf-8")) doc = __rhino_doc__ TOL = 0.01 PID = P["pier_id"] FB = P["footing"]["z_bottom"] MARK = {m: (v["dia"], v["shape"]) for m, v in P["rebar_marks"].items()} DIA = {d: float(d[1:]) for d, _ in MARK.values()} CL_RGB = tuple(P["display"]["centreline_colour"]) FT_RGB = tuple(P["display"]["footing_layer_colour"]) def layer(path, color): parent = -1 parts = path.split("::") for i in range(1, len(parts) + 1): idx = doc.Layers.FindByFullPath("::".join(parts[:i]), -1) if idx < 0: lay = Rhino.DocObjects.Layer() lay.Name, lay.Color = parts[i - 1], Color.FromArgb(*color) if parent >= 0: lay.ParentLayerId = doc.Layers[parent].Id idx = doc.Layers.Add(lay) parent = idx return parent ROT = math.radians(P["footing"].get("rot_deg", 0.0)) def turn(pts): """Foundation axes -> pier axes (counter-clockwise ROT about the origin).""" if not ROT: return pts c, s = math.cos(ROT), math.sin(ROT) return [(x * c - y * s, x * s + y * c, z) for x, y, z in pts] def min_r(dia): d = DIA[dia] return ((2 * d if d <= 16 else 3.5 * d) + d) / 2 def poly(pts, dia): pl = rg.PolylineCurve([rg.Point3d(*p) for p in pts]) if len(pts) < 3: return pl return rg.Curve.CreateFilletCornersCurve(pl, min_r(dia), TOL, math.radians(1)) or pl def add_bar(curve, mark, occ, design_len, src): dia, shape = MARK[mark] pipes = rg.Brep.CreatePipe(curve, DIA[dia] / 2, False, rg.PipeCapMode.Flat, False, TOL, math.radians(1)) if not pipes or not pipes[0].IsSolid: raise RuntimeError(f"{mark} {occ}: pipe failed") common = dict(mark=mark, dia=dia, shape=shape, occurrence=occ, host=f"{PID}-FT", anchor_hosts="", design_length=f"{design_len:.3f}", coupler_length="0.000", src=src) for geo, lay, prefix in ((curve, layer(f"{PID}::철근::중심선", CL_RGB), f"{PID}-RC"), (pipes[0], layer(f"{PID}::철근::기초::{mark}", FT_RGB), f"{PID}-R")): attr = ObjectAttributes() attr.LayerIndex = lay oid = f"{prefix}-{mark}-{occ}" attr.Name = oid attr.SetUserString("id", oid) for k, v in common.items(): attr.SetUserString(k, v) gid = doc.Objects.AddBrep(geo, attr) if isinstance(geo, rg.Brep) else doc.Objects.AddCurve(geo, attr) if gid == System.Guid.Empty: raise RuntimeError(f"{oid}: add failed") def main(): for o in list(doc.Objects): oid = o.Attributes.GetUserString("id") or "" if oid.startswith((f"{PID}-R-B", f"{PID}-RC-B")): doc.Objects.Delete(o, True) fr = P["footing_rebar"] n = 0 for g in fr["groups"]: h, z, leg = g["a"] / 2, FB + g["z"], g.get("leg", 0) for v in g["pos"]: if g["axis"] == "Y": ends = [(v, -h, z), (v, h, z)] else: ends = [(-h, v, z), (h, v, z)] pts = ends if not leg else [(ends[0][0], ends[0][1], z + leg), ends[0], ends[1], (ends[1][0], ends[1][1], z + leg)] add_bar(poly(turn(pts), MARK[g["mark"]][0]), g["mark"], f"{g['axis'].lower()}{v:+.0f}", g["a"] + 2 * abs(leg) + g.get("lap", 0), g.get("src", "")) n += 1 hp = fr["hoops"] sx, sy = hp.get("half_x", hp.get("half")), hp.get("half_y", hp.get("half")) for zz in hp["levels"]: z = FB + zz pts = [(-sx, 0, z), (-sx, -sy, z), (sx, -sy, z), (sx, sy, z), (-sx, sy, z), (-sx, 0.0, z)] add_bar(poly(turn(pts), MARK[hp["mark"]][0]), hp["mark"], f"z{zz:.0f}", hp["design_length"], hp.get("src", "")) n += 1 vt = fr["verticals"] if "points" in vt: where = [tuple(q) for q in vt["points"]] else: where = [(x, y) for i, x in enumerate(vt["grid_x"]) for j, y in enumerate(vt["grid_y"]) if (i + j) % 2 == vt["parity"]] lb, lt = vt.get("leg_bottom", vt.get("leg", 0)), vt.get("leg_top", vt.get("leg", 0)) ux, uy = (1, 0) if vt.get("leg_axis", "X") == "X" else (0, 1) for x, y in where: z0, z1 = FB + vt["z0"], FB + vt["z0"] + vt["a"] pts = [(x + ux * lb, y + uy * lb, z0), (x, y, z0), (x, y, z1), (x + ux * lt, y + uy * lt, z1)] add_bar(poly(turn(pts), MARK[vt["mark"]][0]), vt["mark"], f"x{x:+.0f}y{y:+.0f}", vt["a"] + lb + lt, vt.get("src", "")) n += 1 doc.Views.Redraw() print(json.dumps({"footing_bars": n})) main()