# exec'd inside Rhino via execute_rhino_code: g={}; exec(open(path,encoding='utf-8').read(), g); g['run'](shot) import scriptcontext as sc import Rhino import System from System.Drawing import Size, Color SCR = r"C:\Users\User\AppData\Local\Temp\claude\D--Rhino-MCP-rhino-mcp-main\f46b47bc-9105-4079-9b62-fcbee31b26ae\scratchpad" OUT = SCR + r"\shots" def all_objs(): st = Rhino.DocObjects.ObjectEnumeratorSettings() st.HiddenObjects = True st.NormalObjects = True st.LockedObjects = True st.IncludeLights = False st.IncludeGrips = False return sc.doc.Objects.GetObjectList(st) def state_path(): return SCR + r"\hidden_state.txt" def save_state(): doc = sc.doc ids = [] for o in doc.Objects.GetObjectList(Rhino.DocObjects.ObjectEnumeratorSettings()): pass return None def run(shot): doc = sc.doc import os if not os.path.isdir(OUT): os.makedirs(OUT) layers = shot["layers"] # list of layer-path prefixes to show names = shot.get("names") # optional name substrings (applies to rebar objects only) show_solids = shot.get("solids", []) # exact layer paths of concrete to show for o in all_objs(): ln = doc.Layers[o.Attributes.LayerIndex].FullPath vis = False for s in show_solids: if ln == s: vis = True for p in layers: if ln == p or ln.startswith(p + "::"): if names: ok = False for n in names: if n in o.Name: ok = True if ok: vis = True else: vis = True # skip centerline curves unless asked if "중심선" in ln and not shot.get("centerline", False): vis = False if vis: doc.Objects.Show(o, True) else: doc.Objects.Hide(o, True) view = doc.Views.ActiveView vp = view.ActiveViewport mode = None for d in Rhino.Display.DisplayModeDescription.GetDisplayModes(): if d.EnglishName == shot.get("mode", "Ghosted"): mode = d if mode: vp.DisplayMode = mode pr = shot["view"] if pr == "Front": vp.SetProjection(Rhino.Display.DefinedViewportProjection.Front, "Front", False) elif pr == "Right": vp.SetProjection(Rhino.Display.DefinedViewportProjection.Right, "Right", False) elif pr == "Top": vp.SetProjection(Rhino.Display.DefinedViewportProjection.Top, "Top", False) else: vp.SetProjection(Rhino.Display.DefinedViewportProjection.Perspective, "Perspective", False) c = shot["cam"] vp.SetCameraLocations(Rhino.Geometry.Point3d(c[3], c[4], c[5]), Rhino.Geometry.Point3d(c[0], c[1], c[2])) b = shot["box"] bb = Rhino.Geometry.BoundingBox(Rhino.Geometry.Point3d(b[0], b[1], b[2]), Rhino.Geometry.Point3d(b[3], b[4], b[5])) vp.ZoomBoundingBox(bb) view.Redraw() vs = vp.Size k = shot.get("k", 2.0) w = int(vs.Width * k) h = int(vs.Height * k) bmp = view.CaptureToBitmap(Size(w, h), False, False, False) bmp.Save(OUT + "\\" + shot["file"]) xf = vp.GetTransform(Rhino.DocObjects.CoordinateSystem.World, Rhino.DocObjects.CoordinateSystem.Screen) res = [] for p in shot.get("pts", []): q = Rhino.Geometry.Point3d(p[0], p[1], p[2]) q.Transform(xf) res.append("%.1f,%.1f" % (q.X * k, q.Y * k)) open(OUT + "\\" + shot["file"] + ".txt", "w").write(("%d,%d" % (w, h)) + chr(10) + chr(10).join(res)) return shot["file"] def restore(): doc = sc.doc f3 = Rhino.FileIO.File3dm.Read(doc.Path) hid = set() for ob in f3.Objects: if not ob.Attributes.Visible: hid.add(str(ob.Attributes.ObjectId)) f3.Dispose() n = 0 for o in all_objs(): if str(o.Id) in hid: doc.Objects.Hide(o, True) n += 1 else: doc.Objects.Show(o, True) doc.Views.Redraw() return n