我想在一张图中遍历所有的设备,并得到设备的名称。
以下是我所拥有的:
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.Electrical.ElectricalEquipment‘
无法将“Autodesk.Revit.DB.Element”类型转换为
有什么建议吗?
发布于 2010-09-10 00:35:05
eViews是一个Element列表,而您正在尝试对它们进行迭代,就好像它们是ElectricalEquipment。除非Element继承了ElectricalEquipment,或者有一个显式的cast运算符,否则您将无法做到这一点。
如果将for循环更改为:
foreach(Element element in eViews)
{
Disp.Append("\n" + element);
}它将编译,但是它可能不会产生所需的结果。
https://stackoverflow.com/questions/3681518
复制相似问题