How to use RhinoCommon to batch export detail views from layout

I need to batch export detail drawings from layout views to PDF, but I currently don’t have a clear approach. Here is the code I have so far. Can anyone help me with this?@Dale

 protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.DocObjects.Tables.ViewTable viewTable = Rhino.RhinoDoc.ActiveDoc.Views;
            var pageViews = doc.Views.GetPageViews();
            var dir = "C:\\Users\\Administrator\\Desktop\\";
            int dpi = 600;

            foreach (var pageView in pageViews)
            {
                var pdf = Rhino.FileIO.FilePdf.Create();
                DetailViewObject[] detailView = pageView.GetDetailViews();
                foreach (var detailViewItem in detailView)
                {
                    detailViewItem.IsActive = true;
                }
            }
            return Result.Success;
        }
    }

Hi @Fan,

Seems to me you should just print to PDF. Am I confused?

– Dale

I hope to use RhinoCommon to automate batch printing of detail views in layouts. As shown in the image, there are three views in total, but with the code below, I can only print the content of view 1 at a time, and I am unable to access views 2 and 3.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    Rhino.DocObjects.Tables.ViewTable viewTable = Rhino.RhinoDoc.ActiveDoc.Views;
    string dir = "C:\\Users\\jimmy\\Desktop\\";
    int dpi = 600;
    var pvs = doc.Views.GetPageViews();
    foreach (var view in pvs)
    {
        var dvs = view.GetDetailViews();
        foreach (DetailViewObject detail in dvs)
        {
            var pdf = Rhino.FileIO.FilePdf.Create();
            view.SetPageAsActive();
            view.SetActiveDetail(detail.Id);
            view.SetPageAsActive();
            int w = Convert.ToInt32(view.PageHeight);
            int h = Convert.ToInt32(view.PageWidth);
            System.Drawing.Size size = new System.Drawing.Size(Convert.ToInt32(h * 600 / 25.4), Convert.ToInt32(w * 600 / 25.4));
            Rhino.Display.ViewCaptureSettings settings = new Rhino.Display.ViewCaptureSettings(view, size, dpi);
            settings.RasterMode = false;
            double res = settings.Resolution;
            pdf.AddPage(settings);
            string filePath = System.IO.Path.Combine(dir, detail.Id.ToString() + ".pdf");
            pdf.Write(filePath);

        }
    }

    return Result.Success;
}

You want to print each detail into a separate PDF? And why do you have views outside of the “paper”?