Batch viewport capture to image

unhandled
(Amohiudd) #1

I am using the Rhino Inside Convert console app example to capture viewports to bitmaps and save them to disk as a sort of thumbnail preview for each file.
I put this code inside the obj conversion loop.

        var Views = Rhino.RhinoDoc.ActiveDoc.Views.GetViewList(true, false);
        foreach (var view in Views)
        {
          var img = view.CaptureToBitmap(true, true, true);
          img.Save(string.Format("C:\\Some\\Directory\\\\Rhino.Inside.Output\\{some-filename}.png", runCount.ToString(), view.ActiveViewport.Name), System.Drawing.Imaging.ImageFormat.Png);
          img.Dispose();
        }

I am getting
“External component has thrown an exception”
However, one image is being written correctly to disk. No OBJ conversion is happening.
What might be going wrong ? Any help appreciated.
Thanks

(Nathan 'jesterKing' Letwory) #2

You should attach Visual Studio 2017 to the process, then capture all .NET exceptions prior to entering the loop. Then see if the callstack gives any clues.

Paste here if you can’t figure out from that.

(Amohiudd) #3

Thanks for replying.
In my folder of 3 3dms, only one file is being converted and image is being saved. On attaching a debugger, the correct number of filepaths are read (in this case - 3) but it enters the loop only once.
There are no errors in the console. This is the only thing I found in the debug output.
Exception thrown: 'System.Runtime.InteropServices.SEHException' in RhinoCommon.dll

I have enabled breaking on all CLR exceptions.

(Nathan 'jesterKing' Letwory) #5

@fraguada can you have a look, as this is your sample project?

1 Like
(Luis Fraguada) #6

I’m seeing the same behavior over on my side and cannot detect the cause of the exception when calling view.CaptureToBitmap. I’ll keep investigating.

(Luis Fraguada) #7

When looping through files, you could do something like this:

// Change the original extension to .png
var pngPath = System.IO.Path.ChangeExtension(file, ".png");

var imgScript = string.Format("_-ViewCaptureToFile \"{0}\" _Enter", pngPath);
RhinoApp.RunScript(imgScript, false);

This obviously doesn’t loop through the views in the file, and is a simple workaround, but we need to dig a bit more before finding the issue you’ve reported.

(Amohiudd) #8

Thanks. This will do for now, however I was trying to send the bitmap data over a POST request. Now I will have to read from disk after writing.