This sample shows how the BoundingBoxIntersectsFilter can be used to find elements that penetrate ceilings in the model.
The host file contains 2 ceilings, 2 columns, and a RVT link that contains 3 Generic Model elements. There are also 3 shaft openings in the ceiling so that there is no interference between the ceilings and the elements going through them.
This API code analyzes the bounding box of each ceiling and finds all elements in all files (including the current RVT and links) whose bounding box intersects the ceiling’s bounding box. The results are shown in a dialog and written to a parameter of the ceiling category.
public void FindPenetrations()
{
Document hostDoc = this.ActiveUIDocument.Document;
string data = "";
LogicalOrFilter columnGenericModelfilter = new LogicalOrFilter(new ElementCategoryFilter(BuiltInCategory.OST_Columns), new ElementCategoryFilter(BuiltInCategory.OST_GenericModel));
using (Transaction t = new Transaction(hostDoc, "Find Penetrations"))
{
t.Start();
foreach (Ceiling ceiling in new FilteredElementCollector(hostDoc).OfClass(typeof(Ceiling)))
{
data += "--- Ceiling - " + ceiling.Name + " (id = " + ceiling.Id + ") ---\n";
// define an Outline based on the Bounding Box of this ceiling
Outline outline = new Outline(ceiling.get_BoundingBox(null).Min, ceiling.get_BoundingBox(null).Max);
string paramData = "";
// search for penetrations in all open documents which will include RVT Links and native geoemtry in this RVT
foreach (Document doc in this.Application.Documents)
{
// find elements that pass the Column/Generic Model filter and whose Bounding Box intersects the outline of this Ceiling
foreach (Element e in new FilteredElementCollector(doc).WherePasses(columnGenericModelfilter).WherePasses(new BoundingBoxIntersectsFilter(outline)))
{
data += e.Category.Name + " - " + e.Name + " - " + Path.GetFileName(e.Document.PathName) + " - " + e.Id.IntegerValue + "\n";
paramData += e.Name + " - " + Path.GetFileName(e.Document.PathName) + " - " + e.Id.IntegerValue + "\n";
}
}
ceiling.get_Parameter("Penetrating Elements").Set(paramData);
data += "\n";
}
t.Commit();
}
TaskDialog.Show("Intersections",data);
}