Message 1 of 2
Can't filter Parts using ElementIntersectsSolidFilter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am trying to retrieve parts belonging to a given space, but when trying to filter them using ElementIntersectsSolidFilter, I don't get any parts.. When using the same filter but instead of Parts I use walls for example, I can successfully filter them out. It seems like a bug. I've attached a sample project to reproduce the issue and this is the code that gets this weird behavior:
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Test;
[Transaction(TransactionMode.Manual)]
public class TestPart : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,ref string message,ElementSet elements)
{
var uiApp = commandData.Application;
var uiDoc = uiApp.ActiveUIDocument;
var doc =uiDoc.Document;
var activeView = doc.ActiveView;
var space = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_MEPSpaces)
.WhereElementIsNotElementType()
.First();
var options = new Options();
options.ComputeReferences = true;
options.DetailLevel = ViewDetailLevel.Undefined;
var geoElemSpace = space.get_Geometry(options);
Solid solid = null;
foreach (var geo in geoElemSpace)
{
if (geo is Solid)
{
solid = geo as Solid;
break;
}
if (geo is GeometryInstance geoInst)
{
if (geoInst.GetInstanceGeometry().First() is Solid s1)
{
solid = s1;
break;
}
}
}
var filter = new ElementIntersectsSolidFilter(solid);
var part = new FilteredElementCollector(doc)
.WhereElementIsNotElementType()
.WherePasses(filter)
.OfType<Part>()
.FirstOrDefault();
return Result.Succeeded;
}
}