Automate Layout

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


      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)
            detail.DetailGeometry.IsProjectionLocked = true;
            detail.DetailGeometry.SetScale(1, doc.ModelUnitSystem, 1, doc.PageUnitSystem);
          doc.Views.ActiveView = pageview;



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.

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:

Is this a C# component in grasshopper? I need to do the same thing as you, automate the creation of layouts using border curves. I have a very basic understanding of code but am familiar with grasshopper. How can I use this script?