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
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.UnlockBits()
bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
rhinoView.Close()
sc.doc.Views.RedrawEnabled = True
if __name__ == "__main__":
captureAllNamedViews()
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…
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.