开发者

Revit MEP 2011 C# iterate through all equipment

I want to iterate through all the equipment in a drawing and get the开发者_JAVA技巧 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?


eViews is a list of Element whereas you're trying iterate over them as though they're ElectricalEquipment. Unless Element inherits from ElectricalEquipment or has an explicit cast operator, you won't be able to do this.

If you change your for loop to:

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

It will compile, however it might not produce the required outcome.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜