您的位置:首页 > 其它

Revit API相交过滤BoundingBoxIntersectsFilter

2011-10-13 08:41 357 查看
根据一线条,过滤与之相交的元素。
[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(0, 0, 0), new XYZ(100, 100, 100));
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: