如何计算所有元素类似于FilteredElementCollector符号特殊设备的家族?

发布于 2025-01-19 17:59:25 字数 279 浏览 0 评论 0 原文

当我使用 DesignAutomation (Autodesk Forge) 通过获取 FilteredElementCollector lstEleCollector = new FilteredElementCollector (doc, doc.ActiveView.Id); 来计算 Revit 文件中可见的 BuiltInCategory.OST_SpecialityEquiosystem 元素的数量时 但我意识到设计自动化中没有Active View概念。那么有没有办法统计rvt文件中出现的所有元素呢?

When I use DesignAutomation (Autodesk Forge) to count the number of BuiltInCategory.OST_SpecialityEquiosystem elements visible on the Revit file by getting the FilteredElementCollector lstEleCollector = new FilteredElementCollector (doc, doc.ActiveView.Id);
.But I realized that there is no Active View concept in Design Automation. So is there a way to count all the elements that appear in the rvt file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亣腦蒛氧 2025-01-26 17:59:25

要计算文档中给定类别的所有元素,您应该使用

FilteredElementCollector collector = new FilteredElementCollector(doc);
ICollection<Element> collection = collector.OfCategory(BuiltInCategory.OST_SpecialityEquiosystem)
    .ToElements();
int count = collection.Count;

但是,这将为您提供文档中的所有元素。要在给定视图中找到元素,您需要知道视图ID。如果您不知道视图ID,则可以迭代文档中的所有视图并找到所需的视图。

FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views);
foreach (Autodesk.Revit.DB.View v in collector.ToElements())
{
    if (v && v.Name == "My Special View")
        viewId = v.Id;
}

然后,您可以使用此 viewID 而不是 doc.activeview.id 来调用您已经知道的API。

FilteredElementCollector lstEleCollector = new FilteredElementCollector (doc, viewId);
ICollection<Element> collection = lstEleCollector.OfCategory(BuiltInCategory.OST_SpecialityEquiosystem)
    .ToElements();
int count = collection.Count;

还请参考我们的非常基本的 forge-countdeleteblewalls-revit- revit 代码代码执行类似的示例您正在尝试的事情。它在给定文档中计算墙壁,门,地板和窗户。

To count all elements of a given category in a document you should use FilteredElementCollector.OfCategory():

FilteredElementCollector collector = new FilteredElementCollector(doc);
ICollection<Element> collection = collector.OfCategory(BuiltInCategory.OST_SpecialityEquiosystem)
    .ToElements();
int count = collection.Count;

This will however give you all elements in the document. To find elements in a given view, you will need to know the view id. If you do not know the view id, you can iterate through all views in a document and find the view you are looking for.

FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views);
foreach (Autodesk.Revit.DB.View v in collector.ToElements())
{
    if (v && v.Name == "My Special View")
        viewId = v.Id;
}

Then you can call the API you already know with this viewId instead of doc.ActiveView.Id.

FilteredElementCollector lstEleCollector = new FilteredElementCollector (doc, viewId);
ICollection<Element> collection = lstEleCollector.OfCategory(BuiltInCategory.OST_SpecialityEquiosystem)
    .ToElements();
int count = collection.Count;

Also refer our very basic forge-countdeletewalls-revit code sample which does something similar to what you are attempting. It counts walls, doors, floors and windows in a given document.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文