When attempting to render and save in the “Raytraced” (Cycles) mode, the image is written to disk prior to any passes being generated. I’ve researched this for several hours and tried a number of approaches, to no avail.
How does one save the image only after a specified number of passes have completed? (I don’t necessarily have to set the number of passes in the script- using the number of passes specified in Cycles preferences would be acceptable.)
Why not just script the _-ViewCaptureToFile command, using Rhino.RhinoApp.RunScript. The command line version allows you to specify the number of passes.
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).
Nathan,
I probably won’t have a chance to test this today, but thank you as well. You are correct that I’m trying to stay disciplined and only use dashed commands when there’s no other option.