Revit API相交过滤BoundingBoxIntersectsFilter

根据一线条,过滤与之相交的元素。
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmdFilter : IExternalCommand
{
    
public Result Execute(ExternalCommandData cmdData, ref string messages, ElementSet elements)
    {
        UIDocument uiDoc 
= cmdData.Application.ActiveUIDocument;

        Transaction ts 
= new Transaction(uiDoc.Document, "revit.5d6d.com");
        ts.Start();
            
        
//与outLine相交的元素,比较多,有相机,测试点,项目基点,墙,风管,只要是相交的。
        Outline outLine = new Outline(new XYZ(000), new XYZ(100100100));
        BoundingBoxIntersectsFilter filter 
= new BoundingBoxIntersectsFilter(outLine);
        FilteredElementCollector collector 
= new FilteredElementCollector(uiDoc.Document);
        IList
<Element> elems = collector.WherePasses(filter).ToElements();
        
foreach (Element el in elems)
        {
            TaskDialog.Show(
"all", el.Name + "|" + el.Category.Name);
        }
        
//与outLine相关的墙,第二个参数为false可以得到相交的墙,为true得不到,有待研究。
        BoundingBoxIntersectsFilter invertFilter = new BoundingBoxIntersectsFilter(outLine, false);
        collector 
= new FilteredElementCollector(uiDoc.Document);
        IList
<Element> noIntersectWalls = collector.OfClass(typeof(Wall)).WherePasses(invertFilter).ToElements();
        
foreach (Element el in noIntersectWalls)
        {
            TaskDialog.Show(
"wall", el.Name + "|" + el.Category.Name);
        }
        
//
        TaskDialog.Show("count", elems.Count + "|" + noIntersectWalls.Count);

        ts.Commit();

        
return Result.Succeeded;
    }
}
from:http://revit.5d6d.com/thread-1270-1-1.html
posted @ 2011-10-13 08:41  大气象  阅读(2104)  评论(2编辑  收藏  举报
http://www.tianqiweiqi.com