我想迭代绘图中的所有设备并获取设备的名称。
这就是我所拥有的:
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'
有什么建议吗?
答案 0 :(得分:0)
eViews是Element
的列表,而您正在尝试迭代它们,就好像它们是ElectricalEquipment
一样。除非Element
继承自ElectricalEquipment
或具有明确的强制转换运算符,否则您将无法执行此操作。
如果您将for循环更改为:
foreach(Element element in eViews)
{
Disp.Append("\n" + element);
}
它会编译,但它可能无法产生所需的结果。