Revit API相交过滤BoundingBoxIntersectsFilter
根据一线条,过滤与之相交的元素。
from:http://revit.5d6d.com/thread-1270-1-1.html
[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;
}
}
[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;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。