-ViewCaptureToFile in C# (or C++)


I have a simple question. How would I go about automating the ViewCaptureToFile in C# (or maybe in C++ if it is easier, although I doubt). And I am talking about “full” option where I can determine which View I want (in code), set the resolution and the output file path?

Is there a “code” way, or only the RunScript way? If only RunScript, then what would be the right syntax?


HI @dimcic,
I have an old script lying around in python which i used to capture named views to bitmaps.
It’s all Rhinocommon so it should pretty much translate the same to C# (except the saving part).

Have a look if this helps you along :slight_smile:

import Rhino
import scriptcontext as sc
import System

def captureAllNamedViews():
    folder = System.Environment.SpecialFolder.Desktop
    path = System.Environment.GetFolderPath(folder)

    sc.doc.Views.RedrawEnabled = False
    for i, viewInfo in enumerate(sc.doc.NamedViews):
        # create new viewCapture object
        viewCapture = Rhino.Display.ViewCapture()
        name = viewInfo.Name
        rhinoView = sc.doc.Views.Add(name, Rhino.Display.DefinedViewportProjection.Top, viewInfo.Viewport.ScreenPort, True)
        sc.doc.NamedViews.Restore(i, rhinoView.ActiveViewport)

        viewCapture.Width = rhinoView.Size.Width
        viewCapture.Height = rhinoView.Size.Height

        bitmap = viewCapture.CaptureToBitmap(rhinoView)
        if bitmap:
            filename = System.IO.Path.Combine(path + "\\" + name, ".png");
            bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
    sc.doc.Views.RedrawEnabled = True
if __name__ == "__main__":

Here is a cheap sample in C#:

– Dale

How do I specify display mode for the temporarily created RhinoView?

I did this
rhinoView.ActiveViewport.DisplayMode = a_display_mode
but after export everything is still in wireframe

for a gh component I did it like this,maybe this helps?

Rhino.Display.DisplayModeDescription displaymode = Rhino.Display.DisplayModeDescription.FindByName(display);
                    System.Drawing.Bitmap image = view.CaptureToBitmap(new System.Drawing.Size(w, h), displaymode);
1 Like

It worked! Thanks!
This CaptureToBitmap() is a method of more than one class and the one from ViewCapture doesn’t have overload with a DisplayModeDescription parameter. A little confusing…


somehow the captures wouldn’t “render” the object correctly in display modes other than shaded, rendered and wireframe. It was set to “Artistic” but it’s just wireframe with that papyrus background…

What could be the problem?

Hi ,
I `ve never noticed that,since I never used the Artistic mode, but I now that I tried the same happened to me.
After changing the displaymode manually to Artisitc(and then back to another), the object rendered correctly.

I have no idea why this happens.

maybe worthy of a bug report?