Revit MEP 2011 C#遍历所有设备

时间:2010-09-10 00:28:25

标签: c# revit-api

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

这就是我所拥有的:

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'

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

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

如果您将for循环更改为:

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

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