There is most likely an issue with the Dynamo implementation of creating FilterRules as providing an integer for a YesNo parameter is completely valid.
Here’s a starting point for creating an FilterIntegerRule and a corresponding ParameterFilterElement:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import List
doc = DocumentManager.Instance.CurrentDBDocument
param_id = ElementId(IN[0])
# Get ParameterElement from Parameter's ElementId
param_elem = doc.GetElement(param_id)
definition = param_elem.GetDefinition()
binding_map = doc.ParameterBindings
binding = binding_map.Item[definition]
category_set = binding.Categories.GetEnumerator()
cat_ids = [cat.Id for cat in category_set]
# Convert Python list to .NET List<ElementId>
cat_ids_list = List[ElementId](cat_ids)
cat_ids_valid = ParameterFilterUtilities.RemoveUnfilterableCategories(cat_ids_list)
rule = ParameterFilterRuleFactory.CreateEqualsRule(param_id, 1)
# Convert single FitlerRule to List<FilterRule>
rules = List[FilterRule]([rule])
TransactionManager.Instance.EnsureInTransaction(doc)
pfe = ParameterFilterElement.Create(doc, 'Yes No Test', cat_ids_valid, rules)
TransactionManager.Instance.TransactionTaskDone()
OUT = pfe, pfe.Id
YesNo.dyn (8.9 KB)
Here’s a more elaborate explanation on what’s going on:
Add references to the Revit API and import everything from the Autodesk.Revit.DB namespace
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
Add a reference to RevitServices from a Dynamo DLL and import the DocumentManager (to access the current Revit document) and the TransactionManager (to allow us to modify the document)
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
Import List from the System.Collections.Generic namespace so that we can use native .NET Lists when required.
from System.Collections.Generic import List
Given the parameter’s Id, as an integer, cast it to an ElementId and get the corresponding ParameterElement from the current document.
doc = DocumentManager.Instance.CurrentDBDocument
param_id = ElementId(IN[0])
param_elem = doc.GetElement(param_id)
Get the Parameter’s Definition from the ParameterElement. Get the document’s BindingMap which relates all of the Parameters to their Definitions. Then get the binding of the specific Parameter we have provided.
definition = param_elem.GetDefinition()
binding_map = doc.ParameterBindings
binding = binding_map.Item[definition]
Get the parameter’s categories from the binding we just retrieved.
category_set = binding.Categories.GetEnumerator()
Get the ElementId of each Category contained within the CategorySet.
cat_ids = [cat.Id for cat in category_set]
Convert our Python list to a .NET List so that it will be a valid argument in our next method.
cat_ids_list = List[ElementId](cat_ids)
Remove all categories which cannot be used in creating a FilterRule.
cat_ids_valid = ParameterFilterUtilities.RemoveUnfilterableCategories(cat_ids_list)
Create our Equals rule with a value of 1 (or “Yes” in the context of a YesNo parameter). Then, convert the single rule to a .NET list of FilterRules.
rule = ParameterFilterRuleFactory.CreateEqualsRule(param_id, 1)
rules = List[FilterRule]([rule])
Create the actual ParameterFilterElement called “Yes No Test”.
TransactionManager.Instance.EnsureInTransaction(doc)
pfe = ParameterFilterElement.Create(doc, 'Yes No Test', cat_ids_valid, rules)
TransactionManager.Instance.TransactionTaskDone()
OUT = pfe, pfe.Id