Revit MEP 2011 C# 迭代所有设备

发布于 2024-09-18 16:16:04 字数 942 浏览 7 评论 0原文

我想迭代绘图中的所有设备并获取设备的名称。

这是我所得到的:

UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;

// get all PanelScheduleView instances in the Revit document.
FilteredElementCollector fec = new FilteredElementCollector(doc);
ElementClassFilter EquipmentViewsAreWanted = 
  new ElementClassFilter(typeof(ElectricalEquipment));
fec.WherePasses(EquipmentViewsAreWanted);
List<Element> eViews = fec.ToElements() as List<Element>;

StringBuilder Disp = new StringBuilder();

foreach (ElectricalEquipment element in eViews)
{
    Disp.Append("\n" + element.);
}

System.Windows.Forms.MessageBox.Show(Disp.ToString());

我在 foreach 循环中收到以下错误:

无法将类型“Autodesk.Revit.DB.Element”转换为 'Autodesk.Revit.DB.Electrical.ElectricalEquipment'

有什么建议吗?

I want to iterate through all the equipment in a drawing and get the name of the equipment.

Here is what I have:

UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;

// get all PanelScheduleView instances in the Revit document.
FilteredElementCollector fec = new FilteredElementCollector(doc);
ElementClassFilter EquipmentViewsAreWanted = 
  new ElementClassFilter(typeof(ElectricalEquipment));
fec.WherePasses(EquipmentViewsAreWanted);
List<Element> eViews = fec.ToElements() as List<Element>;

StringBuilder Disp = new StringBuilder();

foreach (ElectricalEquipment element in eViews)
{
    Disp.Append("\n" + element.);
}

System.Windows.Forms.MessageBox.Show(Disp.ToString());

I get the following error at the foreach loop:

Cannot convert type 'Autodesk.Revit.DB.Element' to
'Autodesk.Revit.DB.Electrical.ElectricalEquipment'

Any suggestions?

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

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

发布评论

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

评论(1

自在安然 2024-09-25 16:16:04

eViews 是 Element 的列表,而您尝试迭代它们,就好像它们是 ElectricalEquipment 一样。除非 Element 继承自 ElectricalEquipment 或具有显式强制转换运算符,否则您将无法执行此操作。

如果将 for 循环更改为:

foreach(Element element in eViews)
{
    Disp.Append("\n" + element);
}

它将编译,但可能不会产生所需的结果。

eViews is a list of Element whereas you're trying iterate over them as though they're ElectricalEquipment. Unless Element inherits from ElectricalEquipment or has an explicit cast operator, you won't be able to do this.

If you change your for loop to:

foreach(Element element in eViews)
{
    Disp.Append("\n" + element);
}

It will compile, however it might not produce the required outcome.

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