def ClearList(primList):
result = []
for sublist in primList:
if sublist is "":
continue
elif sublist is None:
continue
if isinstance(sublist, list):
sublist = ClearList(sublist)
if not sublist:
continue
result.append(sublist)
return result
OUT = ClearList(IN[0])
the OUT Dynamo Wrapper is capricious with certain objects
here a solution
import sys
import clr
import System
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
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
ueWrapper = next((m for m in clr.GetClrType(Revit.Elements.ElementWrapper)\
.GetMethods() if m.Name == "Wrap"), None)
if ueWrapper is None:
raise Exception("Error Method", "method 'Revit.Elements.ElementWrapper.Wrap' not found")
views = FilteredElementCollector(doc).OfClass(View).ToElements()
outlist = []
for i in views:
iswrapable = Revit.Elements.ElementWrapper.Wrap(i, True)
if iswrapable is None :
outlist.append(ueWrapper.Invoke(None, (i, True) ))
else:
outlist.append(i)
OUT = outlist
outlist=[]
views = FilteredElementCollector(doc).OfClass(View).ToElements()
for view in views:
x=view.ViewType
if view.ViewType != ViewType.ThreeD:
outlist.append(view)
OUT = outlist
I provide my python function version to collect all views in a document and also removing the funny nulls but showing the all the corresponding view types in the document, that means 3D View templates , system browser, project browser are available with ID .
I tried in a project and I got this list of view types:
thanks to the suggestion of @c.poupin I could do some investigation and make it work as wanted:
import sys
import clr
import System
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk
clr.AddReference("RevitNodes")
import Revit
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
def WrapUnwrapElements(elements):
# Get method Revit.Elements.ElementWrapper.Wrap
ueWrapper = next((m for m in clr.GetClrType(Revit.Elements.ElementWrapper)\
.GetMethods() if m.Name == "Wrap"), None)
if ueWrapper is None:
raise Exception("Error Method", "method 'Revit.Elements.ElementWrapper.Wrap' not found")
outlist = []
for i in elements:
iswrapable = Revit.Elements.ElementWrapper.Wrap(i, True)
if iswrapable is None :
outlist.append(ueWrapper.Invoke(None, (i, True)))
else:
outlist.append(i)
return outlist
def GetViewType(view):
if hasattr(view, "ViewType"): return str(view.ViewType)
else: return None
def GetAllViews(doc):
collector = FilteredElementCollector(doc).OfClass(View).ToElements()
# Apply the WrapUnwrapElements function
wrapped_views = WrapUnwrapElements(collector)
allviews = [view for view in wrapped_views if isinstance(view, Autodesk.Revit.DB.View) or 'View3D' == str(view)]
view_dict = {}
for view in allviews:
view_type = GetViewType(view)
if view_type is None: # Handle views with None type
view_type = "3DViewTemplate"
if view_type not in view_dict:
view_dict[view_type] = [] # initialize the list for this view type
view_dict[view_type].append(view) # append the view to its respective list
return view_dict
def GetAllViewTemplates(doc):
collector = FilteredElementCollector(doc).OfClass(View).ToElements()
# Apply the WrapUnwrapElements function
wrapped_views = WrapUnwrapElements(collector)
templates = [view for view in wrapped_views if (isinstance(view, Autodesk.Revit.DB.View) and hasattr(view, "IsTemplate") and view.IsTemplate) or 'View3D' == str(view)]
view_dict = {}
for view in templates:
view_type = GetViewType(view)
if view_type is None: # Handle views with None type
view_type = "3DViewTemplate"
if view_type not in view_dict:
view_dict[view_type] = [] # initialize the list for this view type
view_dict[view_type].append(view) # append the view to its respective list
return view_dict
OUT = {"All Views in Document": GetAllViews(doc), "All View Templates in Document": GetAllViewTemplates(doc)}