EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

萧闫子 发表于 2014-1-15 12:35:36

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



这个问题看似比较复杂,首先要考虑数据库中的对象时具有几何属性,另外还要判断是否在当前视图可见。所幸的是Revit API提供了一个非常好的FilteredElementCollector 的重载构造函数,可以方便简单高效获得所有的可见对象 view plaincopy
public FilteredElementCollector(
    Document document,
    ElementId viewId
)
第一个参数指明从哪个文档或模型文件,第二个参数设置希望获取哪个视图中可见的对象。下面是实现这个功能的代码。关键代码只有一行。 酷吧!<p style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px; "></p><p style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px; "></p><div style="line-height: 26px; font-family: 'Courier New'; background-color: white; color: black; font-size: 8pt; "><p><span style="color: blue; line-height: 16px; ">public</span><span style="line-height: 16px; "><span style="color: blue; ">class</span><span style="color: rgb(43, 145, 175); ">RevitCommand</span> :<span style="color: rgb(43, 145, 175); ">IExternalCommand</span></span></p><p><span style="line-height: 16px; ">{</span></p><p><span style="line-height: 16px; ">    </span><span style="color: blue; line-height: 16px; ">public</span><span style="line-height: 16px; "><span style="color: rgb(43, 145, 175); ">Result</span> Execute(<span style="color: rgb(43, 145, 175); ">ExternalCommandData</span> commandData,<span style="color: blue; ">ref</span><span style="color: blue; ">string</span> messages,<span style="color: rgb(43, 145, 175); ">ElementSet</span> elements)</span></p><p><span style="line-height: 16px; ">    {</span></p><p> </p><p><span style="line-height: 16px; ">      </span><span style="color: rgb(43, 145, 175); line-height: 16px; ">UIApplication</span><span style="line-height: 16px; "> app = commandData.Application;</span></p><p><span style="line-height: 16px; ">      </span><span style="color: rgb(43, 145, 175); line-height: 16px; ">Document</span><span style="line-height: 16px; "> doc = app.ActiveUIDocument.Document;</span></p><p> </p><p><span style="line-height: 16px; ">      </span><span style="color: rgb(43, 145, 175); line-height: 16px; ">FilteredElementCollector</span><span style="line-height: 16px; "> collector =</span><span style="color: blue; line-height: 16px; ">new</span><span style="line-height: 16px; "><span style="color: rgb(43, 145, 175); ">FilteredElementCollector</span>(doc, doc.ActiveView.Id);</span></p><p><span style="line-height: 16px; ">      </span><span style="color: rgb(43, 145, 175); line-height: 16px; ">TaskDialog</span><span style="line-height: 16px; ">.Show(</span><span style="color: rgb(163, 21, 21); line-height: 16px; ">"visible element"</span><span style="line-height: 16px; ">,</span><span style="color: rgb(163, 21, 21); line-height: 16px; ">"number is "</span><span style="line-height: 16px; "> + collector.ToElementIds().Count.ToString());</span></p><p> </p><p><span style="line-height: 16px; ">      </span><span style="color: blue; line-height: 16px; ">return</span><span style="line-height: 16px; "><span style="color: rgb(43, 145, 175); ">Result</span>.Succeeded ;</span></p><p><span style="line-height: 16px; ">    }</span></p><p><span style="line-height: 16px; ">}</span></p></div>返回值就存储在collector变量中。运行结果会在对话框显示可见对象的数量转载请复制以下信息:原文链接: http://blog.csdn.net/joexiongjin/article/details/7641140作者:叶雄进 , Autodesk ADN

雁田佬 发表于 2014-2-20 14:12:37

顶......
楼下跟上.....

页: [1]
查看完整版本: 获取一个视图中所有可见的对象