Get Unused Filters

Get unused filters

2 min read

Within Revit, certain elements cannot be easily purged by a user. For example, the out-of-the-box ‘Purge Unused’ command (Manage > Settings > Purged Unused) cannot delete filters, view templates or line styles. While manually deleting these items is possible, this process isn’t always straightforward. For example, when deleting filters, Revit will indiscriminately delete filters without forewarning you that the filter is currently in use. This limitation means there is no way to differentiate between filters in use and those that aren’t.

Purge Unused

Identifying unused filters with Dynamo

To help solve this problem, it is possible to use Python and Dynamo. In the example below, the (IronPython2) Python node is doing all the heaving lifting and collecting all the unused filters. A simple conditional statement is then used to allow the user to review the filters before deleting them. Note that, like other elements in Revit, there must be at least one type in the project. Therefore even if no filters are used, there will always be at least one.

Get unused filters
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("System.Core")
import System.Linq
clr.ImportExtensions(System.Linq)

clr.AddReference("RevitAPI")
import Autodesk.Revit
from Autodesk.Revit.Exceptions import InvalidOperationException
from Autodesk.Revit.DB import *

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

def GetFilterIds(view):
  filterIds = None
  try:
    filterIds = view.GetFilters()
  except InvalidOperationException, e:
    filterIds = None
  return filterIds

def GetUsedFilterIds(doc):
  views = FilteredElementCollector(doc).OfClass(View).ToElements()
  usedFilterIds = []
  for view in views:
    viewFilterIds = []
    try:
      viewFilterIds = view.GetFilters()
    except InvalidOperationException, e:
      pass # this exception happens when a view doesn't support filters
    usedFilterIds.extend(viewFilterIds)
  return usedFilterIds

def GetUnusedFilters(doc):
  usedFilterIds = GetUsedFilterIds(doc).ToList[ElementId]()
  if len(usedFilterIds) > 0:
  	unusedFilters = FilteredElementCollector(doc).OfClass(ParameterFilterElement).Excluding(usedFilterIds).ToElements()
  else:
  	unusedFilters = FilteredElementCollector(doc).OfClass(ParameterFilterElement).ToElements()
  return list(f.ToDSType(True) for f in unusedFilters)

#The inputs to this node will be stored as a list in the IN variables.
doc = DocumentManager.Instance.CurrentDBDocument

#Assign your output to the OUT variable.
OUT = GetUnusedFilters(doc)

Conclusion

Revit really should allow users to purge all unused elements in their model. However, as shown, certain elements cannot be purged using out-of-the-box functionality. But with a little assistance from Dynamo, we can automate the process and help keep models clean and lean.

6 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Renumber Viewports
Premium

Renumber viewports

Use Dynamo to automatically renumber the detail number parameter of viewports placed on sheets, streamlining documentation.

Axonometric Crop Region
Premium

Axonometric crop region

Learn how to use Dynamo to batch update the crop region of axonometric views with a consistent buffer offset.

Create multi-category schedules
Premium

Create multi-category schedules

Learn how to use Dynamo to automate the batch creation of multi-category schedules for use in a room data sheet.

Copyright​

© 2025 Parametric Monkey
Parametric Monkey and the Parametric Monkey logo are trademarks of Parametric Monkey Pty Ltd.

Discover more from Parametric Monkey

Subscribe now to keep reading and get access to the full archive.

Continue reading

Subscribe

Gain full access to tutorials and newsletter updates.

CONTACT US

Drop us a message and someone from our team will be in touch with you shortly.

BOOM!

Thank you for your interest. Someone from our team will be in touch soon.

WORKSHOP APPLICATION

To find out about upcoming public workshops or to organise a private workshop, please submit the following contact form and we’ll be in touch soon.