Get Element by Type/Family Name (Element Parameter Filter)

Often times you might want to get all elements of a certain Type. And usually it's not a fun process with Revit API, but I have something to make it as easy as it can be. Below you will find a snippet of a function to Get All Elements by Type Name We will use ElementParameterFilter to create a function to get elements by Type Names. It needs:

  • Parameter Id to create ParameterValueProvider

  • Evaluator (FilterStringEquals) in this case Also notice that there were changes in Revit API for this class so I will account for that too

  • Then we can provide all of this to create ElementParameterFiler

  • And we can use this filter for FilteredElementCollector with WherePasses

# -*- coding: utf-8 -*-

doc      = __revit__.ActiveUIDocument.Document
app      = __revit__.Application
rvt_year = int(app.VersionNumber)


def get_elements_by_type_name(type_name):
    """Function to get Elements by Type Name."""

    # CREATE RULE
    param_id    = ElementId(BuiltInParameter.ALL_MODEL_TYPE_NAME)
    f_param     = ParameterValueProvider(param_id)
    f_evaluator = FilterStringEquals()

    # Revit API has changes
    if rvt_year < 2023:
        f_rule = FilterStringRule(f_param, FilterStringEquals(), type_name,True)
    else:
        f_rule = FilterStringRule(f_param, FilterStringEquals(), type_name)

    # CREATE FILTER
    filter_type_name = ElementParameterFilter(f_rule)

    # GET ELEMENTS
    return FilteredElementCollector(doc).WherePasses(filter_type_name)\
                          .WhereElementIsNotElementType().ToElements()
                           
# Get Elements                           
elements = get_elements_by_type_name('Type Name')
print(elements)

You can also modify it a little to get all elements by Family Name like this:

# -*- coding: utf-8 -*-

doc      = __revit__.ActiveUIDocument.Document
app      = __revit__.Application
rvt_year = int(app.VersionNumber)


def get_elements_by_family_name(family_name):
    """Function to get Elements by Family Name."""

    # CREATE RULE
    param_id    = ElementId(BuiltInParameter.ALL_MODEL_FAMILY_NAME)
    f_param     = ParameterValueProvider(param_id)
    f_evaluator = FilterStringEquals()

    # Revit API has changes
    if rvt_year < 2023:
        f_rule = FilterStringRule(f_param, FilterStringEquals(), family_name, True)
    else:
        f_rule = FilterStringRule(f_param, FilterStringEquals(), family_name)

    # CREATE FILTER
    filter_type_name = ElementParameterFilter(f_rule)

    # GET ELEMENTS
    return FilteredElementCollector(doc).WherePasses(filter_type_name)\
                          .WhereElementIsNotElementType().ToElements()
                           
# Get Elements                           
elements = get_elements_by_family_name('Filled Region')
print(elements)



⌨️ Happy Coding!
Erik Frits