Can't filter Parts using ElementIntersectsSolidFilter

Can't filter Parts using ElementIntersectsSolidFilter

rcrdzmmrmnn
Advocate Advocate
228 Views
1 Reply
Message 1 of 2

Can't filter Parts using ElementIntersectsSolidFilter

rcrdzmmrmnn
Advocate
Advocate

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;
	}
}

 

0 Likes
229 Views
1 Reply
  • bug
Reply (1)
Message 2 of 2

rcrdzmmrmnn
Advocate
Advocate

Has anyone come across this problem before? I suppose I could find parts belonging to a space or room by brute-force checking for intersections using the BooleanOperationsUtils class, but from my understanding, that would be much slower than using the ElementIntersectsSolid filter. Since a project is likely to have many parts, I'm trying to avoid this approach. Any input would be appreciated.

0 Likes