Use CaptureToBitmap / Capture Viewport to File?

I am not sure where to look for using this with Python - RhinoCommon SDK ? I don’t see anything in Python info, did I miss anything?

I have a basic script that zomms viewports and changes Top to a Special (Pen copy) display mode which I then Capture to a PNG.

Trying to add the Capture part to the script but not sure where to look. Any advice?

Thanks, Randy

Hi Randy,

If some functionality is not available through RhinoCommon SDK, you can always use the native Rhino command and call it with rs.Command:

import rhinoscriptsyntax as rs

rs.Command("_-ViewCaptureToFile D:\somePhoto.jpg _Enter")

… and you can script in all the size options as well in the command string…

You can also do this with rhinocommon natively:

import Rhino
import System.Drawing
def rCommonCap(filePath, viewportName,scaleFactor):
    RhinoDocument = Rhino.RhinoDoc.ActiveDoc
    view = RhinoDocument.Views.Find(viewportName, False)
    vp = view.ActiveViewport
    size = System.Drawing.Size(vp.Size.Width*scaleFactor,vp.Size.Height*scaleFactor)
    capture = view.CaptureToBitmap(size)
    capture.Save(filePath);
3 Likes

Thanks @djordje , @Helvetosaur & @andheum

The rs.Command will come in handy!

Would this be in the rs,Command (ViewCaptureToFile options) ?

The RhinoCommon method looks sweet. @andheum, is there a way to save as Jpeg or PNG for example / default setting?

Randy

It is dependent on the extension in the filename, but be cautious - I have come across a bug that trying to save as JPG sometimes results in it saving a PNG but setting the extension to JPG - which makes it preview in windows but not open properly in many other applications, can be quite confusing.

Something like:

import rhinoscriptsyntax as rs

comm=""" -_ViewCaptureToFile D:\\Desktop\\TestCap.png 
_Width=1200 _Height=900 _Scale=1 
_DrawGrid=_No _DrawWorldAxes=_No _DrawCPlaneAxes=_No 
_TransparentBackground=_No _Enter"""

rs.Command(comm,False)

@Helvetosaur Thanks, just searching where to find Rhino Commandline options . :smile:

On the command line? :smiley:

Where I can find the options that can be added to the command, Like you did with ViewCaptureToFile then adding _Width _Height for example. Sometimes those options are not obvious when working outside of the GUI known as Rhino :astonished:

As in Scripting

Well, I actually wasn’t kidding. The only way to find these options IS on the command line.

Type -_ViewCaptureToFile (with the dash), give it a file name and Enter, then see the options…

With rs.Command, you are just calling stuff as if you were on the command line. The options are the same as found in the normal Rhino commands. You do need to script them in the correct sequence, and occasionally there are some fun “specialties” that you need to test by trial-and-error…

–Mitch

Thanks @Helvetosaur , got it. I was trying to find the correct syntax to write out each option as when to use an underscore or exclamation mark etc…

« Randy

This is in the Rhino Help