Revit MEP 2011 C# 迭代所有设备
我想迭代绘图中的所有设备并获取设备的名称。
这是我所得到的:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
eViews 是
Element
的列表,而您尝试迭代它们,就好像它们是ElectricalEquipment
一样。除非Element
继承自ElectricalEquipment
或具有显式强制转换运算符,否则您将无法执行此操作。如果将 for 循环更改为:
它将编译,但可能不会产生所需的结果。
eViews is a list of
Element
whereas you're trying iterate over them as though they'reElectricalEquipment
. UnlessElement
inherits fromElectricalEquipment
or has an explicit cast operator, you won't be able to do this.If you change your for loop to:
It will compile, however it might not produce the required outcome.