Zooming Layout Details in .Net

Hi,

I’ve created a new Layout and Detail via Code.
Now I’m trying to zoom into a special object at the scale (1:5)

The Object should be centered and the the view scale should be set.

I’ve had a look at http://wiki.mcneel.com/developer/rhinocommonsamples/addlayout

Here is my code.

//Add Detail
DetailViewObject detail = pageView.AddDetailView(“MyDetail”, new Point2d(20, 20), new Point2d(1000, 800), Rhino.Display.DefinedViewportProjection.Top);

            RhinoApp.WriteLine(objectIds[0].ToString());
            if (detail != null)
            {
                pageView.SetActiveDetail(detail.Id);
                doc.Objects.UnselectAll();
                //Select an Object
                doc.Objects.Select(objectIds[0]);
                detail.Viewport.ZoomExtentsSelected();
                detail.DetailGeometry.SetScale(5, doc.ModelUnitSystem, 1, doc.PageUnitSystem);
                // Commit changes tells the document to replace the document's detail object
                // with the modified one that we just adjusted                    
                detail.CommitChanges();
            }
            pageView.SetPageAsActive(); 

I replaced the

detail.Viewport.ZoomExtents();

and deleted the line:

detail.DetailGeometry.IsProjectionLocked = true;

My Code doesn’t work though - and I can’t find a working solution. So I was wondering if anyone could help me with finding a solution.

Thanks
Martin

I found a solution:

detail.CommitViewportChanges();

Didn’t realize that I had to submitt the Viewport Changes Separately

Hi @dale .

I was wondering in the example you posted - Is the code really executing the

detail.Viewport.ZoomExtents();

Since the default behavior with the creation of a detail, is to zoom the extends - the result would be the same.
But isn’t

detail.CommitViewportChanges();
needed to make the Zoom Extends work - theoretically.

Thanks,
Martin

The default zoom you get when you create a detail doesn’t leave the same 'border" that a Viewport.ZoomExtents does. So it might be worth doing after you create your detail. And yes, calling CommitViewportChanges is needed.