Create a ParameterFilter by Python

Hi All,

active_view = doc.ActiveView
category_name = “Structural Rebar”
parameter_name = “Comments”
parameter_value = “CLASH”
RuleTye = “equals”

I want a Create a parameterFilter by python given data as above.
please guide me how to complete my task.

chatgpt:

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.")

Unless you specifically need to do it in python, you can use designscript to do the same process also. The last output would be your list.
Just FYI.

image

1 Like