Open View from Viewport on Sheet

Hello all,

Its been a while since I have posted (took a long vacation) but I am back and excited for all the new changes. I wanted to share a quick script I just made for opening views from a sheet rather than having to find them in the Project Browser.

image

I had to go back a few Package updates to get @john_pierson code for Pick Model Element but it still works great. Viewport.GetView is still available in his most current version.

Big thanks to @Nick_Boyts for providing the code to open a view. The post can be found here.

I chose to use John’s old code rather than the built-in pick elements tool, so you do not need to edit the inputs from the player. In Dynamo player just hit the play button then select the viewport (view on a sheet) you want to open and the view will pop up.

Open View by Viewport_01.dyn (5.4 KB)

Hope it helps,

3 Likes

Hello @Steven, sorry to dig up an old post but I’m wondering if there is a way to get this to work with a list of views. It appears to only work with a single element.

Yes, you just need to add a forloop.

myView = UnwrapElement(IN[0])

for i in views:
(**tab** I cannot add one right now) uw=UnwrapElement(i)
(**tab**) uiapp.ActiveUIDocument.RequestViewChange(uw)

Something like that should work.

I’ve tried to add that but it’s returning an error that ‘views’ are not defined.
I’m not very experienced in python so am likely missing something simple.

views

import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
from Revit.Elements import *
clr.AddReference('System')
from System.Collections.Generic import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB 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
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
myView = UnwrapElement(IN[0])

uiapp.ActiveUIDocument.RequestViewChange(myView)

myView = UnwrapElement(IN[0])

for i in views:
	uw=UnwrapElement(i)
	uiapp.ActiveUIDocument.RequestViewChange(uw)

#Assign your output to the OUT variable.
OUT = "ActiveView set to: " + myView.Name

Sorry about that.

myView = UnwrapElement(IN[0])

Should be

views=IN[0]
1 Like