In Revit’s API, filters are categorized as either fast or slow. Combining these two types can significantly accelerate the filtering process.
Let’s start with an example using the ElementIntersectsSolidFilter, which is a slow filter. When dealing with thousands of elements, the code below can take at least 30-40 seconds to execute:
FilteredElementCollector collector = new FilteredElementCollector(revitDoc);
ElementIntersectsSolidFilter solidFilter = new ElementIntersectsSolidFilter(solid);
collector.WherePasses(solidFilter);
IList<Element> listElement = new List<Element>();
listElement = collector.ToList();
How can we speed this up without compromising the results? The answer is to combine the slow filter with fast filters. In the following example, two fast filters—BoundingBoxIntersectsFilter and BoundingBoxIsInsideFilter—are used alongside ElementIntersectsSolidFilter. This approach yields the same results but runs over ten times faster.
For a deeper understanding of the principle, please refer to the official documentation.
FilteredElementCollector collector = new FilteredElementCollector(revitDoc);
BoundingBoxIntersectsFilter boxFilter = new BoundingBoxIntersectsFilter(new Outline(solid.GetBoundingBox().Min, solid.GetBoundingBox().Max));
BoundingBoxIsInsideFilter boxInsideFilter = new BoundingBoxIsInsideFilter(new Outline(solid.GetBoundingBox().Min, solid.GetBoundingBox().Max));
LogicalOrFilter logicOrFilter = new LogicalOrFilter(boxFilter, boxInsideFilter);
ElementIntersectsSolidFilter solidFilter = new ElementIntersectsSolidFilter(solid);
collector.WherePasses(logicOrFilter);
collector.WherePasses(solidFilter);
IList<Element> listElement = new List<Element>();
listElement = collector.ToList();
While this code runs fine in Debug mode, it causes errors in Release mode, especially during background idle operations. These errors can trigger fatal crashes in Revit. This is a known major bug in the ElementIntersectsSolidFilter that affects both Revit API versions 17 and 18.
So, how can we work around this bug? After over ten days of investigation, a simple solution was found. Instead of filtering elements directly with ElementIntersectsSolidFilter, use it only to verify if each element meets the criteria after applying fast filters. This approach does not significantly increase processing time and avoids the API bug.
FilteredElementCollector collector = new FilteredElementCollector(revitDoc);
BoundingBoxIntersectsFilter boxFilter = new BoundingBoxIntersectsFilter(new Outline(solid.GetBoundingBox().Min, solid.GetBoundingBox().Max));
BoundingBoxIsInsideFilter boxInsideFilter = new BoundingBoxIsInsideFilter(new Outline(solid.GetBoundingBox().Min, solid.GetBoundingBox().Max));
LogicalOrFilter logicOrFilter = new LogicalOrFilter(boxFilter, boxInsideFilter);
collector.WherePasses(logicOrFilter);
IList<Element> listElement = new List<Element>();
listElement = collector.ToList();
foreach(Element elem in listElement)
{
FilteredElementCollector elementCollector = new FilteredElementCollector(revitDoc, new List<ElementId>() { elem.Id });
ElementIntersectsSolidFilter solidFilter = new ElementIntersectsSolidFilter(solid);
elementCollector.WherePasses(solidFilter);
if(elementCollector != null && elementCollector.Count() > 0)
{
DoSomeThing(elem);
}
elementCollector.Dispose();
}













Must log in before commenting!
Sign Up