I cobbled together this script from snippets I found on the forum. It works great, except the actual view capture speed is very slow. I’m using Rhino 8.

import Rhino as rc
import rhinoscriptsyntax as rs
import scriptcontext as sc
import ghpythonlib as gh
import ghpythonlib.treehelpers as th
import os
import System
cameraLocs = loc
file_names = th.tree_to_list(file_name, 0)
opt_names = th.tree_to_list(opt_name, 0)
bboxes = th.tree_to_list(bbox, 0)
def zoom_to_geometry(rectangle, padding=10):
"""
Creates a boundary around the provided point and zooms the Rhino view to this boundary.
Args:
rectangle: Bounding rectangle of view.
padding: Additional space around the boundary to ensure the geometry is not clipped in the view.
"""
# Calculate the bounding box of the rectangle, including padding if necessary
bbox = rectangle.BoundingBox
if padding > 0:
# Expand the bounding box by the padding amount
bbox.Inflate(padding)
# Zoom to the bounding box of the rectangle
sc.doc.Views.ActiveView.ActiveViewport.ZoomBoundingBox(bbox)
sc.doc.Views.Redraw()
def captureViewportToFile(file_path, view=None, size=System.Drawing.Size(2500, 1000)):
view = sc.doc.Views.ActiveView;
if view:
view_capture = rc.Display.ViewCapture()
view_capture.Width = size.Width
view_capture.Height = size.Height
view_capture.ScaleScreenItems = False
view_capture.DrawAxes = False
view_capture.DrawGrid = False
view_capture.DrawGridAxes = False
view_capture.TransparentBackground = False
bitmap = view_capture.CaptureToBitmap(view)
if bitmap:
folder = System.Environment.SpecialFolder.Desktop
path = System.Environment.GetFolderPath(folder)
bitmap.Save(file_path, System.Drawing.Imaging.ImageFormat.Png);
if run:
for ind, pt in enumerate(opt_names):
if ind == 0:
for idx, bbox in enumerate(bboxes[ind]):
if idx < 4:
zoom_to_geometry(bbox, padding)
print(file_names)
captureViewportToFile(directory + file_names[ind][idx] + ".png");
The ifs in the run loop are to limit the number of view captures for debugging. Right now, if I just capture the screen at the viewport resolution, it takes a few seconds per view. If I change the capture size, though, the capture can take anywhere between 15 to 60 seconds. I have approx. 40 views to capture, so I’m hoping this can be sped up. I’m not too familiar with the bitmap.Save function, so I’m hoping there is an approach to speed up the capture out there somewhere.