Expected IList[FilterRule], got FilterStringRule

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

Looks like you are passing a single filter rule to the constructor when you should be passing a list. I’m suspecting you’re feeding a flat list of filter rules instead of a nested list.

Also - are you aware that this kind of functionality exists in Dynamo 1.2 (node ParameterFilterElement.ByRules)? No need to code it yourself.

1 Like

Thanks Andreas. I got it solved already. Cheers !

hi, Letuandinh. Could you explain how you solved above question? I got the same problem.

Hi, you need to turn the flatten list of rules into nested list.

thanks, i will try.

I have the same problem too. How do you get the Rules into nested lists?

Thanks

@Ben_Veasey, the iList errors?

I am referring to the iList errors. The each of the ‘Rules’ needed to be in a nested List. My rubbish Python ability struggled with this so I used an OOTB List.Chop node. This now works :slight_smile:

1 Like