获取一个视图中所有可见的对象

 

转载请复制以下信息:

原文链接: http://blog.csdn.net/joexiongjin/article/details/7641140

作者:  叶雄进 , Autodesk ADN

 

这个问题看似比较复杂,首先要考虑数据库中的对象时具有几何属性,另外还要判断是否在当前视图可见。

所幸的是Revit API提供了一个非常好的FilteredElementCollector 的重载构造函数,可以方便简单高效获得所有的可见对象

public FilteredElementCollector(
	Document document,
	ElementId viewId
)


第一个参数指明从哪个文档或模型文件,第二个参数设置希望获取哪个视图中可见的对象。

下面是实现这个功能的代码。关键代码只有一行。 酷吧!

  [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]

publicclassRevitCommand :IExternalCommand

{

    publicResult Execute(ExternalCommandData commandData,refstring messages,ElementSet elements)

    {

 

      UIApplication app = commandData.Application;

      Document doc = app.ActiveUIDocument.Document;

 

      FilteredElementCollector collector =newFilteredElementCollector(doc, doc.ActiveView.Id);

      TaskDialog.Show("visible element","number is " + collector.ToElementIds().Count.ToString());

 

        returnResult.Succeeded ;

    }

}

返回值就存储在collector变量中。运行结果会在对话框显示可见对象的数量

 

 

 

你可能感兴趣的:(Revit,对象过滤--,找到目标对象,Revit,二次开发中级技术)