Zooming a new view

If you are creating a new view and then want to use the UIView.Zoom method, you need to make the new view the active view and then refresh the view. If you don’t, the attempt to zoom will be futile.

public void createNewViewAndZoom()
{
    Document doc = this.ActiveUIDocument.Document;
    UIDocument uidoc = this.ActiveUIDocument;
    ViewFamilyType vft3d = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast<ViewFamilyType>().FirstOrDefault(q => q.ViewFamily == ViewFamily.ThreeDimensional);
    View view = null;
    using (Transaction t = new Transaction(doc, "make views"))
    {
        t.Start();
        view = View3D.CreateIsometric(doc, vft3d.Id);
        t.Commit();
    }
    zoom(uidoc, view);            
}

private void zoom(UIDocument uidoc, View view)
{
    // YOU NEED THESE TWO LINES OR THE ZOOM WILL NOT HAPPEN!
    uidoc.ActiveView = view;
    uidoc.RefreshActiveView();
    
    UIView uiview = uidoc.GetOpenUIViews().Cast<UIView>().FirstOrDefault(q => q.ViewId == view.Id);
    uiview.Zoom(5);
}
Advertisements

One thought on “Zooming a new view

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s