all_filters = FilteredElementCollector(doc).OfClass(FilterElement).ToElements()
for filter in all_filters:
cateoryIds = filter.GetCategories()
for cateoryId in cateoryIds:
category = Category.GetCategory(doc,cateoryId)
category_name = category.Name
paras = filter.GetElementFilterParameters()
for para in paras:
parameter_element = doc.GetElement(para)
parameter_name = doc.GetElement(para).Name
Spent a lot time yesterday on apidocs and on google, but itĀ“s all pretty confusing, and as some methods like .GetRules() did not work for me i thought there must have been a lot of changes in the api in the last years and IĀ“m only finding old codeā¦
Will try my luck again and see if your code and diagram will help me understand this whole filter rule stuff.
IĀ“m in Revit 22, the parameter you mentioned is just a project parameter.
So this is my current status:
ā¦
Still some things i donĀ“t understand.
I have to get deep down to the rule to get the parameter value, but i get the parameter from the parameter filter element, that canĀ“t be right because every rule could have a different parameterā¦
edit:
now also works for BuiltInParameters:
parameter_filters = FilteredElementCollector(doc).OfClass(ParameterFilterElement).ToElements()
BIPs = System.Enum.GetValues(BuiltInParameter)
if parameter_filters:
for parameter_filter in parameter_filters:
element_filter = parameter_filter.GetElementFilter() #Returns an ElementFilter representing the combination of rules used by this filter.
if element_filter:
element_parameter_filters = element_filter.GetFilters() #A filter used to match elements by one or more parameter filter rules.
for element_parameter_filter in element_parameter_filters:
rules = element_parameter_filter.GetRules() #Returns the set of rules contained in this filter.
for rule in rules:
if isinstance(rule, Autodesk.Revit.DB.FilterStringRule):
value = rule.RuleString
evaluator = rule.GetEvaluator()
elif isinstance(rule, Autodesk.Revit.DB.FilterValueRule):
value = rule.RuleValue
evaluator = rule.GetEvaluator()
elif isinstance(rule, Autodesk.Revit.DB.FilterElementIdRule):
value = rule.RuleValue
elif isinstance(rule, Autodesk.Revit.DB.FilterInverseRule):
pass
cateoryIds = parameter_filter.GetCategories()
for cateoryId in cateoryIds:
category = Category.GetCategory(doc,cateoryId)
category_name = category.Name
outlist =[]
parameter_ids = parameter_filter.GetElementFilterParameters() #Retrieves a list of the parameters associated with each rule in the filter.
for parameter_id in parameter_ids:
if parameter_id.IntegerValue < 0:
for bip in BIPs:
if ElementId(bip) == parameter_id:
parameter_element = bip
else:
parameter_element = doc.GetElement(parameter_id)
parameter_name = parameter_element.Name
Got it all working now, but IĀ“m confused about the āFilterInverseRuleā.
All filters I want to collect are from the type āFilterInverseRuleā, I had to get the InnerRule to get my desired informations.
def section_type_filter():
parameter_filters = FilteredElementCollector(doc).OfClass(ParameterFilterElement).ToElements()
if parameter_filters:
for parameter_filter in parameter_filters:
element_filter = parameter_filter.GetElementFilter() #Returns an ElementFilter representing the combination of rules used by this filter.
if element_filter:
element_parameter_filters = element_filter.GetFilters() #A filter used to match elements by one or more parameter filter rules.
for element_parameter_filter in element_parameter_filters:
rules = element_parameter_filter.GetRules() #Returns the set of rules contained in this filter.
for rule in rules:
if isinstance(rule, Autodesk.Revit.DB.FilterInverseRule):
inner_rule = rule.GetInnerRule()
if isinstance(inner_rule, Autodesk.Revit.DB.FilterStringRule):
value = inner_rule.RuleString
parameter_id = rule.GetRuleParameter()
if value == section_type_value and parameter_id == section_type_parameter.Id:
return parameter_filter
So far so good, but i really have no idea what this āFilterInverseRuleā is, can someone please explain?
This is one of them, what makes this filter to a āFilterInverseRuleā and how to create such a filter with the revit UI?
The FilterInverseRule basically changes a rule to its opposite. The inversed rule is defined in the InnerRule of the FilterInverseRule. As an example, the rule shown in your screenshot should be a FilterInverseRule that has a FilterStringEquals rule as its InnerRule. Iām not sure what your end goal is here, but perhaps have a look at the Python code of Clockworkās ParameterFilterElement.FilterRuleString node. Itās a recursive function that renders the entire filter rule as a human-readable string (see below).
Regarding the second part of your question: Any time you select an operator that contains a ānotā in the UI (in your example: ādoes not equalā), you are using a FilterInverseRule.