相交过滤器的应用,比几何相交法简便。
Excluding剔除//找到与风管相交的对象,通过相交过滤器。
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class FindIntersectWallsByElement : IExternalCommand
{
public Result Execute(ExternalCommandData
commandData,
ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Transaction trans =
new Transaction(doc,
"ExComm");
trans.Start();
//pick the duct
Selection sel = app.ActiveUIDocument.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element,
"Please pick a duct");
Element duct = doc.GetElement(ref1);
FilteredElementCollector collector =
new FilteredElementCollector(doc);
//相交过滤器
ElementIntersectsElementFilter elementFilter =
new ElementIntersectsElementFilter(duct,
false);
collector.WherePasses(elementFilter);
List<ElementId> excludes =
new List<ElementId>();
excludes.Add(duct.Id);
collector.Excluding(excludes);
//剔除自身
sel.Elements.Clear();
//Add these interseting element to the selection
foreach (Element elem
in collector)
{
sel.Elements.Add(elem);
}
trans.Commit();
return Result.Succeeded;
}
}url:http://greatverve.cnb
logs.com/p/ElementIntersectsElementFilter.html