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”

有什么建议么?

4

1 回答 1

0

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

如果您将 for 循环更改为:

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

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

于 2010-09-10T00:35:05.960 回答