I have a custom command for capturing Layout pages to a file. I’ve typically only had one layout view. I can’t figure out how to determine with Layout view is active. Should page.PageIsActive be True for all layout pages?
The built in ViewCaptureToClipboard command gets the space around the page, which I don’t want.
using System;
using Rhino;
using System.Drawing;
Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc;
var pages = doc.Views.GetPageViews();
foreach (var pagee in pages)
{
// All pages show as active!!
Console.WriteLine($"{pagee.PageName} Active={pagee.PageIsActive}");
}
// This is the hard coded one I want right now, but is not general
var page = pages[1];
System.Drawing.Size size = new Size(page.Size.Width, page.Size.Height);
var capture = new Rhino.Display.ViewCaptureSettings(page, dpi:300) ;
capture.DrawClippingPlanes = true;
capture.DefaultPrintWidthMillimeters = 0.36;
capture.RasterMode = true;
capture.DrawGrid = false;
capture.DrawBackground = false;
System.Drawing.Bitmap image = Rhino.Display.ViewCapture.CaptureToBitmap(capture);
System.Windows.Forms.Clipboard.SetImage(image);
the easiest way to find the selected layout is by casting the active view to a page view and see if it sticks.
var active_view = doc.Views.ActiveView;
if (active_view is RhinoPageView page)
{
//page is set
}
As for your screen capture of the page. I can see that we don’t have a bool exposed that the CaptureToBitmap uses internally for the Print dialog so that it can generate a proper white page background. This is something we can get exposed pretty quickly. If your goal is to capture the layout on a completely transparent background without the page itself displayed in some way then we’ll have a bit more work to do.
Thank you, Travis. I’ll give that a try. Would it make sense for Rhino’s built in ViewCaptureToClipboard and ViewCaptureToFile to do this natively for layouts?
My use case here is typically as part of macro files (ReadCommandFile). So it’s not a complex use case and I’d be perfectly happy to ditch my implementation if Rhino’s had this behavior.
Yes, and both of those commands use the publicly available functions in RhinoCommon as well, so they suffer the same issues. Hopefully its as simple as exposing a couple of the internal overloads for CaptureToBitmap that the Print dialog uses.