🏗️ Revit APIbeginnerElement Selection

Filter Revit Elements by Parameter Value

Learn how to efficiently filter elements in Revit using parameter values with FilteredElementCollector and ParameterFilter.

0 views12/14/2025

Filter Elements by Parameter Value in Revit

Application: Revit API
Category: Filtering & Selection
Difficulty: Beginner
Language: C#

Problem

You need to find all walls in a project that have a specific parameter value, such as all walls with a fire rating of "2 Hour" or all doors from a particular manufacturer.

Solution

Use FilteredElementCollector with a ParameterFilterElement or iterate through elements and check parameter values. For better performance with large models, create a ParameterFilter.

Code Example

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Collections.Generic;
using System.Linq;

public List<Wall> GetWallsByFireRating(Document doc, string fireRating)
{
    List<Wall> matchingWalls = new List<Wall>();
    
    // Collect all walls
    FilteredElementCollector collector = new FilteredElementCollector(doc)
        .OfClass(typeof(Wall))
        .WhereElementIsNotElementType();
    
    foreach (Wall wall in collector)
    {
        // Get fire rating parameter
        Parameter fireRatingParam = wall.get_Parameter(BuiltInParameter.DOOR_FIRE_RATING);
        
        if (fireRatingParam != null && fireRatingParam.HasValue)
        {
            string value = fireRatingParam.AsString();
            if (value == fireRating)
            {
                matchingWalls.Add(wall);
            }
        }
    }
    
    return matchingWalls;
}

// Usage example
public void FindFireRatedWalls(Document doc)
{
    List<Wall> twoHourWalls = GetWallsByFireRating(doc, "2 Hour");
    TaskDialog.Show("Results", $"Found {twoHourWalls.Count} walls with 2-hour fire rating");
}

Advanced: Using ParameterFilter for Better Performance

public List<Wall> GetWallsByFireRatingFast(Document doc, string fireRating)
{
    // Create parameter filter
    ParameterValueProvider provider = new ParameterValueProvider(
        new ElementId(BuiltInParameter.DOOR_FIRE_RATING));
    
    FilterStringRuleEvaluator evaluator = new FilterStringEquals();
    FilterRule rule = new FilterStringRule(provider, evaluator, fireRating, false);
    
    ElementParameterFilter filter = new ElementParameterFilter(rule);
    
    // Apply filter to collector
    FilteredElementCollector collector = new FilteredElementCollector(doc)
        .OfClass(typeof(Wall))
        .WhereElementIsNotElementType()
        .WherePasses(filter);
    
    return collector.Cast<Wall>().ToList();
}

Key Points

  • Always check if a parameter exists before accessing its value
  • Use HasValue to verify the parameter contains data
  • For shared parameters, use LookupParameter("ParameterName") instead of get_Parameter(BuiltInParameter)
  • ParameterFilters execute at the database level and are much faster for large models
  • Remember that parameter names are language-dependent, so BuiltInParameter enums are more reliable

Common Pitfalls

Mistake: Not checking for null parameters

// WRONG - will crash if parameter doesn't exist
string value = wall.get_Parameter(BuiltInParameter.DOOR_FIRE_RATING).AsString();

// CORRECT
Parameter param = wall.get_Parameter(BuiltInParameter.DOOR_FIRE_RATING);
if (param != null && param.HasValue)
{
    string value = param.AsString();
}

Related Topics

  • FilteredElementCollector optimization
  • Custom parameter creation
  • Parameter storage types
  • Shared parameters vs project parameters

Code Example

C#
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Collections.Generic;
using System.Linq;

public List<Wall> GetWallsByFireRating(Document doc, string fireRating)
{
    List<Wall> matchingWalls = new List<Wall>();
    
    // Collect all walls
    FilteredElementCollector collector = new FilteredElementCollector(doc)
        .OfClass(typeof(Wall))
        .WhereElementIsNotElementType();
    
    foreach (Wall wall in collector)
    {
        // Get fire rating parameter
        Parameter fireRatingParam = wall.get_Parameter(BuiltInParameter.DOOR_FIRE_RATING);
        
        if (fireRatingParam != null && fireRatingParam.HasValue)
        {
            string value = fireRatingParam.AsString();
            if (value == fireRating)
            {
                matchingWalls.Add(wall);
            }
        }
    }
    
    return matchingWalls;
}

// Usage example
public void FindFireRatedWalls(Document doc)
{
    List<Wall> twoHourWalls = GetWallsByFireRating(doc, "2 Hour");
    TaskDialog.Show("Results", $"Found {twoHourWalls.Count} walls with 2-hour fire rating");
}