我想添加一个插件来读取包含一串 RevitId 的数据文件并绘制它们。
我不知道如何使用 C# 根据字符串 elementId 在 Revit 中查找给定元素。
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
我知道这会给我一个文档,但我不知道如何获取所有 ID。我正在考虑有一个 foreach 循环来检查元素 id 的字符串与文档中所有元素的字符串,直到找到匹配项。然后,我可以操纵它。
请您参考如下方法:
一种方法是使用 FilteredElementCollector 遍历特定元素类型以获取它们的 elementId。
FilteredElementCollector docCollector = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_Walls);
后跟(如您所建议的):
foreach(Element el in docCollector)
{
ElementId elID = el.Id;
//....
}
修改版本:
List<ElementId> ids = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_Walls).ToElementIds().ToList();
后跟(如您所建议的):
foreach(ElementId elId in ids)
{
//....
}
如果您正在考虑遍历所有元素,我建议您查看来自 The Building Coder: Do Not Filter For All Elements 的这篇博文
