Automatically ZoomToFit Activated View

@cridder asked me this question in an email. Here is an example of hook script that ensures any view you open in Revit is zoomed to fit.

from pyrevit import revit
from pyrevit import EXEC_PARAMS

cview = EXEC_PARAMS.event_args.CurrentActiveView
for view in revit.uidoc.GetOpenUIViews():
    if view.ViewId == cview.Id:

For context, the ZoomToFit() method is a method of UIView class ( so we have to find the UIView instance pointing to the view first

1 Like

Just added revit.active_ui_view to the develop branch to make this a bit easier