Automate Layout

Hi,
From the rhinocommon documentation we got a piece of code that allows to automate the creation of layouts.
However we are stuck when it comes to zoom the view to specific object for each layout. We use a bounding box for each set of object then use the Viewport.ZoomBoundingBox(); but the view doesn’t change.
Any idea?

We use a c# component to execute the script, by the way.

 private void RunScript(bool b, DataTree<Curve> geom, DataTree<Point3d> pt, ref object A)
  {
//Each branch will be on a new layout with different set of curves
//geom: some curves we want to add to the layout
//pt: some points that define the bounding box of the drawing

    if(b)
    {

      for (int i = 0; i < geom.Branches.Count; i++)
      {

        var bbox = new BoundingBox(pt.Branches[i]);
        
        doc.PageUnitSystem = Rhino.UnitSystem.Millimeters;
        var page_views = doc.Views.GetPageViews();
        int page_number = (page_views == null) ? 1 : page_views.Length + 1;
        var pageview = doc.Views.AddPageView(string.Format("A0_{0}", page_number), 1189, 841);
        if( pageview != null )
        {
          Rhino.Geometry.Point2d top_left = new Rhino.Geometry.Point2d(20, 821);
          Rhino.Geometry.Point2d bottom_right = new Rhino.Geometry.Point2d(1169, 20);
          var detail = pageview.AddDetailView("ModelView", top_left, bottom_right, Rhino.Display.DefinedViewportProjection.Top);
          if (detail != null)
          {
            pageview.SetActiveDetail(detail.Id);
            //detail.Viewport.ZoomExtents();
            detail.Viewport.ZoomBoundingBox(bbox);
            doc.Views.Redraw();
            detail.DetailGeometry.IsProjectionLocked = true;
            detail.DetailGeometry.SetScale(1, doc.ModelUnitSystem, 1, doc.PageUnitSystem);
            detail.CommitChanges();
          }
          pageview.SetPageAsActive();
          doc.Views.ActiveView = pageview;
          doc.Views.Redraw();
        }

      }

    }

Hello @tosiho19,

I believe the line detail.DetailGeometry.SetScale(1, doc.ModelUnitSystem, 1, doc.PageUnitSystem); is undoing the ZoomBoundingBox line, try removing it and it should work.

Hi,
Thx unfortunately nope… it doesn’t change anything

Actually it works now, got some issue with the BBox… so the solution is correct

Glad to have helped, @tosiho19 :slight_smile: