Filters are divided into Selection Filters and Rule-based Filters.
For Rule-based Filters, you can refer to my previous article:
Revit Secondary Development: Attaching Filters to Linked Models in Projects

Selection Filters, as the name suggests, allow you to pass a collection of selected element IDs and add them to the view filter. In some scenarios, you need to filter and select specific elements, but when there is no common logic rule for filtering, you can choose to use a selection filter.

Here is my code, which adds code for setting cut background patterns and solid fill styles:

1
2
3
4
5
6
7
8
9
10
11
12
13
var selectionFilter = SelectionFilterElement.Create(doc, "OutRange");
selectionFilter.SetElementIds(targetElementIds);

doc.ActiveView.AddFilter(selectionFilter.Id);

var graphics = doc.ActiveView.GetFilterOverrides(selectionFilter.Id);
graphics.SetCutBackgroundPatternColor(new Autodesk.Revit.DB.Color(255, 0, 0));
graphics.SetCutBackgroundPatternId(PatternId(doc));
graphics.SetCutForegroundPatternColor(new Autodesk.Revit.DB.Color(255, 0, 0));
graphics.SetCutForegroundPatternId(PatternId(doc));
doc.ActiveView.SetFilterOverrides(selectionFilter.Id, graphics);
doc.ActiveView.SetFilterVisibility(selectionFilter.Id, true);

The method for getting the solid fill PatternId is also provided:

1
2
3
4
5
6
7
8
9
10
11
12
13
/// <summary>
/// Get Solid Fill Pattern ID
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
private ElementId PatternId(Document document)
{
var collector = new FilteredElementCollector(document);
collector.OfClass(typeof(FillPatternElement));
var fillPatternElement =
collector.First(q => (q as FillPatternElement).GetFillPattern().IsSolidFill) as FillPatternElement;
return fillPatternElement.Id;
}

Selection Filter (SelectionFilterElement Class) API:

![Image Description](https://cdn.bimath.com/blog/pg/Snipaste_2026-01-04_15-37-04.png)