Hi everyone,
I’m trying to create a list of view filter in corresponding to a list of input FilterRule, I got the error as title, Could someone help to explain and how to fix it. Below is the code. Really appreciate !
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import System
from System.Collections.Generic import *
#The inputs to this node will be stored as a list in the IN variables
dataEnteringNode = IN
# declare all inputs
cats = IN[0]
rules = IN[1]
view = UnwrapElement(IN[2])
filterName = IN[3]
# start a transaction
TransactionManager.Instance.EnsureInTransaction(doc)
# iterate over all categories inputted and create a list of category ids
catList = []
for i in cats:
catList.append(ElementId(i.Id))
# revit api method ParameterFilterElement.Create() only accepts
# typed lists which are not implemented in Python, but we can convert
# a Python list to typed List using System.Collections.Generic module like so
typedCatList = List[ElementId](catList)
# use utility method above to get BuiltInParameter from its name
#create a new rule and add it to the list of rules
# I am enclosing this call in try statement because view
# can already have that filter applied in which case it will
# throw an exception if we attempt to add it again
filterlist = []
for i in filterName:
filterlist.append(i)
# create a new filter based on rules, categories and name
for number in range(len(rules)):
filter = ParameterFilterElement.Create(doc, filterName[number], typedCatList,rules[number])
# add filter to view
view.AddFilter(filter.Id)
# close the transaction
TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable
OUT = filter