Walkthrough: Retrieve Filtered Elements

You can use a filter to select only elements that meet certain criteria. For more information on creating and using element filters, see Iterating the Elements Collection.

This example retrieves all the doors in the document and returns the list of door elements.

Code Region 2-8: Retrieve filtered elements

public ICollection<Element> CreateLogicAndFilter(Autodesk.Revit.DB.Document document)
{
    // Find all door instances in the project by finding all elements that both belong to the door 
    // category and are family instances.
    ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance));

    // Create a category filter for Doors
    ElementCategoryFilter doorsCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors);

    // Create a logic And filter for all Door FamilyInstances
    LogicalAndFilter doorInstancesFilter = new LogicalAndFilter(familyInstanceFilter, doorsCategoryfilter);

    // Apply the filter to the elements in the active document
    FilteredElementCollector collector = new FilteredElementCollector(document);
    IList<Element> doors = collector.WherePasses(doorInstancesFilter).ToElements();
    
    return doors;
}