Hello Dynamo Friends
Is there a direct way to get the Viewport from a View with the revit API?
I searched a lot but could´nt find something.
If there is no direct way then i have to get all viewports on the sheet, get viewIDs and compare.
Rhythm has a node for this, but whats the code?^^
Thankful for any advice
Struggling with my workaround with a strange error:
My viewport has no View.Id? But why?
viewports = IN[0]
for viewport in viewports:
viewId = viewport.ViewId
OUT = viewId
hi, I think you have to add this:
viewports = UnwrapElement(IN[0])
1 Like
Uh, you are so right! Thank you!
So the workaround works, still interrested if there is a better way.
1 Like
Here is the final code to get Viewports from Views
# Get all viewports in document:
viewports = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Viewports).WhereElementIsNotElementType().ToElements()
outlist=[]
# If Input is an item wrap it in a list:
if isinstance(IN[0],list):
views = UnwrapElement(IN[0])
else:
views = [UnwrapElement(IN[0])]
# Get view ID of views:
for view in views:
viewId = view.Id
# Get View ID of viewports:
for viewport in viewports:
viewportId = viewport.ViewId
# output viewports that have the same view ID as the views:
if viewportId == viewId:
outlist.append(viewport)
OUT = outlist
1 Like