BIM World
A Professional BIM Learning Platform


Enhancing Revit Secondary Development: Boosting Filtering Speed and Fixing Bugs in the ElementIntersectsSolidFilter API

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();
}
xuebim
Follow the latest BIM developments in the architecture industry, explore innovative building technologies, and discover cutting-edge industry insights.
← Scan with WeChat
Like(0) 打赏
BIM WORLD » Enhancing Revit Secondary Development: Boosting Filtering Speed and Fixing Bugs in the ElementIntersectsSolidFilter API

Comment Get first!

Must log in before commenting!

 

BIM World, A Professional BIM Learning Platform

Stay updated on the latest architecture trends and share new building technologies.

Contact UsAbout Us

觉得文章有用就打赏一下小编吧

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

Account Login

By signing in, you agree toUser Agreement

Sign Up