View.Viewport - Get Viewport from View

Hello Dynamo Friends :slight_smile:

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 :slight_smile:

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

you can check this out:
https://forum.dynamobim.com/t/get-view-from-viewport-python/74707/2

1 Like

Uh, you are so right! :smiley: 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 :slight_smile:

# 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