from Autodesk.Revit.DB import FilteredElementCollector, ElementParameterFilter, BuiltInParameter, ParameterFilterRuleFactory, ParameterFilterElement
active_view = doc.ActiveView
category_name = "Structural Rebar"
parameter_name = "Comments"
parameter_value = "CLASH"
rule_type = "equals"
# Get the category by name
category = None
collector = FilteredElementCollector(doc, active_view.Id)
for elem in collector.OfCategory(category_name):
category = elem.Category
break
if category:
# Get the parameter by name
parameter = category.GetParameters(parameter_name)[0]
# Create the rule
rule = ParameterFilterRuleFactory.CreateEqualsRule(parameter.Id, parameter_value, True)
# Create the filter
parameter_filter = ElementParameterFilter(rule)
# Create the parameter filter element
with transaction:
parameter_filter_element = ParameterFilterElement.Create(doc, "Parameter Filter", [parameter_filter])
# Assign the filter to the active view
with transaction:
active_view.AddFilter(parameter_filter_element.Id)
# Apply the filter to the elements in the active view
with transaction:
active_view.SetFilterVisibility(parameter_filter_element.Id, True)
else:
print("Category not found.")