Here a script that does a capture using the ViewCapture script. Use this method if you don’t want to use the dashed command version.
# Material switcher
# and Raytraced viewcapturing
import scriptcontext as sc
import Rhino.Render as rr
import Rhino as r
import Rhino.DocObjects as rdob
import System
av = sc.doc.Views.ActiveView
cycles = sc.doc.Views.ActiveView.RealtimeDisplayMode
oldpasses = cycles.MaxPasses
cycles.MaxPasses = 2
def capture_viewport(name):
cycles.Paused = True
view_capture = r.Display.ViewCapture()
view_capture.Width = av.ActiveViewport.Size.Width
view_capture.Height = av.ActiveViewport.Size.Height
view_capture.ScaleScreenItems = False
view_capture.DrawAxes = False
view_capture.DrawGrid = False
view_capture.DrawGridAxes = False
view_capture.TransparentBackground = False
view_capture.RealtimeRenderPasses = 10
bitmap = view_capture.CaptureToBitmap(av)
if bitmap:
folder = System.Environment.SpecialFolder.Desktop
path = System.Environment.GetFolderPath(folder)
filename = System.IO.Path.Combine(path, name + "_raytraced_capture.png")
print("saving ", filename)
bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png)
selobs = [ob for ob in sc.doc.Objects if ob.IsSelected(False)>0]
if len(selobs) > 0:
showroom_materials = [rm for rm in sc.doc.RenderMaterials if rm.Tags and rm.Tags.find("ShowRoom")>-1]
for rm in showroom_materials:
for ob in selobs:
ob.RenderMaterial = rm
ob.CommitChanges()
sc.doc.Views.Redraw()
print("capturing with ", rm.Name)
capture_viewport(rm.Name)
else:
print("no capturing today")
cycles.MaxPasses = oldpasses
cycles.Paused = False
To see this particular script in action you need a 3dm file with one or more materials that have the tag Showroom. Each material should have a good name. Select an object in your model, then run this script. It will create captures, one for each material on the selected object(s).