I am trying to get the views from a list of viewports using Python. I am struggling to find the method that does this. Appreciate any help. See my attempt below.
# CODE
# Get Viewports on Sheet
all_viewports = FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_Viewports).WhereElementIsNotElementType().ToElements()
all_viewports_flat = [ ]
for view in all_viewports:
if isinstance (view,list):
for v in view:
all_viewports_flat.append(v)
else:
all_viewports_flat.append(view)
# Get Views
all_views = []
for viewport in all_viewports_flat:
all_views.append(viewport.GetViews())
import clr
clr.AddReference("RevitAPI")
#import the specific Revit API sections we need, you can also just do import* if you want
from Autodesk.Revit.DB import FilteredElementCollector,BuiltInCategory,Viewport, View
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
viewports = FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_Viewports).WhereElementIsNotElementType().ToElements()
views = []
for viewport in viewports:
viewId = viewport.ViewId
views.append(doc.GetElement(viewId))
OUT = viewports,views