Files
Pier_v1/Code/검토수정/스크립트/c1_p32_capture.py
T
ahnyongjooandClaude Sonnet 5.5 964a841de1 chore(rebar): Pier_T_rebar 작업 폴더 초기 구성 및 외부 의존 파일 통합
- Code\rebar_pipeline, review_pipeline, pier-program을 정션에서 실제 폴더로 전환
- Code\rhino_mcp 및 CLAUDE_rhino배경.md 추가, .mcp.json은 PYTHONPATH로 새 위치 사용
- pier-program 내부 .git 제거(이력은 backup\pier-program_20261028.bundle에 보관)
- worktree 가이드 반영(CLAUDE.local.md, HANDOFF.md)
- D:\Rhino-MCP 경로 참조를 새 위치로 치환

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 11:20:18 +09:00

72 lines
2.7 KiB
Python

#! python3
# capture one Ramp-A P3-2 bar (pipe solid) in the plane of the bar, plus projected pixel positions of key points
import os, json, math, traceback
import Rhino
import Rhino.Geometry as rg
import System
import System.Drawing
HERE = os.path.dirname(os.path.abspath(__file__))
cfg = json.load(open(os.path.join(HERE, "p32_cfg.json"), encoding="utf-8"))
res = {"key": cfg["key"]}
try:
doc = Rhino.RhinoDoc.ActiveDoc
st = Rhino.DocObjects.ObjectEnumeratorSettings()
st.HiddenObjects = True; st.LockedObjects = True; st.NormalObjects = True
for l in doc.Layers:
if not l.IsDeleted:
doc.Layers.ForceLayerVisible(l.Index)
target = None
cen = None
for o in doc.Objects.GetObjectList(st):
if o.Attributes.Name == cfg["pipe"]:
target = o
if o.Attributes.Name == cfg["curve"]:
cen = o
for o in doc.Objects.GetObjectList(st):
if o.Id == target.Id:
doc.Objects.Show(o, True)
else:
doc.Objects.Hide(o, True)
c = cen.Geometry
pts = [c.SegmentCurve(i).PointAtStart for i in range(c.SegmentCount)] + [c.SegmentCurve(c.SegmentCount - 1).PointAtEnd]
T1, T2 = pts[0], pts[-1]
zb = c.GetBoundingBox(True).Min.Z
u = rg.Vector3d(T2.X - T1.X, T2.Y - T1.Y, 0); u.Unitize()
n = rg.Vector3d(u.Y, -u.X, 0)
bb = target.Geometry.GetBoundingBox(True)
mid = bb.Center
view = doc.Views.ActiveView
vp = view.ActiveViewport
vp.ChangeToParallelProjection(True)
vp.SetCameraLocations(mid, mid + n * 6000.0)
vp.CameraUp = rg.Vector3d(0, 0, 1)
bb2 = rg.BoundingBox(bb.Min, bb.Max)
bb2.Inflate(180.0)
vp.ZoomBoundingBox(bb2)
vp.DisplayMode = Rhino.Display.DisplayModeDescription.FindByName("Shaded") or vp.DisplayMode
view.Redraw()
Rhino.RhinoApp.Wait()
cw, ch = vp.Size.Width, vp.Size.Height
W = 1500
H = int(round(W * ch / float(cw)))
sc = W / float(cw)
bmp = view.CaptureToBitmap(System.Drawing.Size(W, H))
png = os.path.join(cfg["out"], "%s.png" % cfg["key"])
bmp.Save(png, System.Drawing.Imaging.ImageFormat.Png)
def px(p):
q = vp.WorldToClient(p)
return [q.X * sc, q.Y * sc]
C1 = rg.Point3d(T1.X, T1.Y, zb)
C2 = rg.Point3d(T2.X, T2.Y, zb)
res.update({"png": png, "size": [bmp.Width, bmp.Height], "T1": px(T1), "T2": px(T2), "C1": px(C1), "C2": px(C2),
"T1_world": [T1.X, T1.Y, T1.Z], "T2_world": [T2.X, T2.Y, T2.Z], "zb": zb, "zt": max(T1.Z, T2.Z)})
except Exception:
res["error"] = traceback.format_exc()
res["done"] = True
json.dump(res, open(os.path.join(cfg["out"], "%s_capture.json" % cfg["key"]), "w", encoding="utf-8"), ensure_ascii=False, indent=1)
try:
Rhino.RhinoDoc.ActiveDoc.Modified = False
except Exception:
pass