Is there a way to do Zoom a view to Fit in Dynamo. Equivalent to mouse middle button double-click.
There should be a Zoom to Fit or Fit to Screen option in the contextual menu…
Looking for Zoom to Fit, programmatically in Dynamo
Oh sorry, that wasn’t clear, this info could be useful to anyone coming here through the search field anyway…
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)
The UIView.ZoomToFit Method is probably even better:
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
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
from Autodesk.Revit.UI import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
views = 
for i in IN:
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.
There is a discussion about opening views through Dynamo, but it does not seem to have a great solution, but read here:
I have used this code for ZoomToFit. Now, I am trying to output the results to save and export as an image. How can I output the view from this node?
You could use this routine to export the image:
doc = DocumentManager.Instance.CurrentDBDocument uiapp = DocumentManager.Instance.CurrentUIApplication views = FilteredElementCollector(doc).OfClass(View).ToElements() for v in views: if v.Name == '*ViewName*': TransactionManager.Instance.ForceCloseTransaction() uiapp.ActiveUIDocument.RequestViewChange(v) TransactionManager.Instance.EnsureInTransaction(doc) options = ImageExportOptions() options.ExportRange = ExportRange.CurrentView options.HLRandWFViewsFileType = ImageFileType.JPEGLossless options.FitDirection = FitDirectionType.Horizontal options.ZoomType = ZoomFitType.FitToPage options.PixelSize = 2048 options.ImageResolution.DPI_600 options.FilePath = r'FILE PATH' exportImage = doc.ExportImage(options) TransactionManager.Instance.TransactionTaskDone()
I hope this would be useful.