Zoom to Fit in Dynamo?

python

#1

Is there a way to do Zoom a view to Fit in Dynamo. Equivalent to mouse middle button double-click.


#2

There should be a Zoom to Fit or Fit to Screen option in the contextual menu…


#3

Looking for Zoom to Fit, programmatically in Dynamo


#4

Oh sorry, that wasn’t clear, this info could be useful to anyone coming here through the search field anyway… :slight_smile:


#5

You can select all elements in the view and use this API method : http://www.revitapidocs.com/2015/6c40c35b-1b2b-1741-dafa-5ab6b1744634.htm

(similar to what happens when you click the green label in watch nodes)


#6

The UIView.ZoomToFit Method is probably even better:

http://www.revitapidocs.com/2017/535f4910-37e0-0f46-924a-443899587d95.htm

import clr

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

for uv in uidoc.GetOpenUIViews():
	if uv.ViewId.Equals( doc.ActiveView.Id ):
		uiview = uv
		break
uiview.ZoomToFit()

OUT = 0

#7

Hi, I am trying out python script. My intend is to get selected views to be zoom to fit. I have selected my views using dynamo nodes, and have made a script. It does not have any respond, only an error that the object does not have attribute zoom to fit. Would need some help here… Thanks alot

import clr

clr.AddReference(‘RevitAPIUI’)
from Autodesk.Revit.UI import *

clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

views = []
for i in IN[0]:
break
i.ZoomToFit()

TransactionManager.Instance.TransactionTaskDone()

OUT=views


#8

Hello @Loy_Seah.

I Believe that the ZoomToFit method refers to the UIView class from the Autodesk.Revit.UI namespace.
As far as I understand it, this means that you can only “ZoomToFit” views that are opened in the model, so that they are part of your Revit UI.

Ref:
http://www.revitapidocs.com/2018.1/2a070256-00f0-5cab-1412-bee5bbfcfc5e.htm

There is a discussion about opening views through Dynamo, but it does not seem to have a great solution, but read here: