Filter elements with python in lists

Hi all,

I’m new to python and want to filter a specific floor type in a view. Now my script works when I just use a string node. Although the problem is that I’m working with the Data Shape package with user input so Dynamo creates a list.

Does anyone could help me out?

Thanks in advance!


ERROR:
File “”, line 33, in
TypeError: expected str, got List[object]

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

user_input = UnwrapElement(IN[0])

collector = FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_Floors).WhereElementIsNotElementType().ToElements()

floors = []
for f in collector:
	if f.Name.Contains(user_input):
		floors.append(f)


OUT = floors

Hi @Glutinator030 ,

Is there a specific reason why you need to use Python instead of Dynamo Nodes? The filtering you are describing can be easily done with OOTB Dynamo Nodes.

Do you have any suggestions? :slight_smile:

Something like this should get you started :smiley:

Hi,
try this

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

user_input = IN[0][0] if isinstance(IN[0], list) else IN[0]

collector = FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_Floors).WhereElementIsNotElementType().ToElements()

floors = []
for f in collector:
	if f.Name in user_input:
		floors.append(f)

OUT = floors
3 Likes

Thanks works perfect!