At some point, every BIM manager or Revit user has encountered a messy model where someone has gone overboard with view filters.
In one project I inherited, someone had created hundreds of view filters, many of which were completely unused—just sitting there, cluttering up the model. Manually deleting them? Not an option.
So, I wrote a Revit API script to automatically detect and remove unused view filters, making cleanup quick and effortless.
How the Script Works
The script starts by collecting all the filters in the model and checking which ones are actually being used in views. If a filter isn’t being used, it gets added to a ‘to-delete’ list. Finally, the script removes all the unused filters in a single transaction.
The script follows these steps:
1️⃣ Collect all views in the model – Filters out views that allow graphics overrides.
2️⃣ Identify filters that are actually being used – Checks view settings to see which filters are applied.
3️⃣ Find unused filters – Compares all filters against the list of used ones.
4️⃣ Delete the unused filters – Uses a Revit transaction to remove them from the model.
Step 1: Get All Views and Identify Used Filters
First, we loop through all views and check which filters are actively in use.
Click to expand source code
public void DeleteViewFilters()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
int viewsFiltersDelete = 0;
int viewsWithFilters = 0;
IList<ElementId> usedFilters = new List<ElementId>();
// Collect all views
var views = new FilteredElementCollector(doc)
.OfClass(typeof(View))
.WhereElementIsNotElementType()
.Cast<View>();
foreach (View v in views)
{
if (v.AreGraphicsOverridesAllowed()) // Ignore views where overrides aren’t allowed
{
foreach (ElementId filterId in v.GetFilters())
{
if (filterId != null)
{
usedFilters.Add(filterId);
viewsWithFilters++;
}
}
}
}
}
Code language: PHP (php)Step 2: Find Unused Filters
Next, we collect all filter elements in the model and compare them against our list of used filters.
Click to expand source code
// Collect all filters
var allFilters = new FilteredElementCollector(doc)
.OfClass(typeof(FilterElement))
.WhereElementIsNotElementType()
.Cast<FilterElement>();
IList<FilterElement> filtersToDelete = new List<FilterElement>();
// Identify unused filters
foreach (FilterElement f in allFilters)
{
if (!usedFilters.Contains(f.Id)) // If a filter is NOT in use, mark it for deletion
{
filtersToDelete.Add(f);
viewsFiltersDelete++;
}
}
Code language: PHP (php)Step 3: Delete Unused Filters
Once the unused filters are identified, we start a Revit transaction and remove them.
Click to expand source code
using (Transaction t = new Transaction(doc, "Delete Unused View Filters"))
{
t.Start();
int count = 0;
try
{
foreach (FilterElement f in filtersToDelete)
{
if (f.Id != null && f.IsValidObject)
{
doc.Delete(f.Id);
count++;
}
}
}
catch (Exception e)
{
TaskDialog.Show("Error", e.ToString());
}
t.Commit();
TaskDialog.Show("Cleanup Complete", "Filters in Use: " + viewsWithFilters.ToString() +
"\nUnused Filters Removed: " + viewsFiltersDelete.ToString() +
"\nTotal Deleted: " + count.ToString());
}
Code language: PHP (php)Unused view filters might seem like a minor annoyance, but they can have a big impact. They slow down your model, make it harder to find the filters you actually need, and create unnecessary complexity.
If you’re dealing with a Revit model that’s overrun with view filters, don’t let them weigh you down.
⚡ This script removed dozens of unnecessary view filters in seconds.
⚡ No more manually sifting through filters to figure out what’s still in use.
⚡ Keeping models clean and optimized makes collaboration easier and performance better.
If your Revit model is cluttered with unused filters, this automation will save you hours of manual cleanup.


No Comments