您的位置:首页 > 其它

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

2012-06-07 11:05 302 查看
转载请复制以下信息:

原文链接: /article/1765013.html

作者: 叶雄进 , 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变量中。运行结果会在对话框显示可见对象的数量
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: