2010-09-10 74 views
0

我想遍歷圖形中的所有設備並獲取設備的名稱。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' 到 「歐特克。 Revit.DB.Electrical.ElectricalEquipment'

有什麼建議嗎?

回答

0

eViews是Element的列表,而您嘗試對它們進行迭代,就好像它們是ElectricalEquipment一樣。除非Element繼承自ElectricalEquipment或者有明確的轉換運算符,否則您將無法執行此操作。

如果for循環更改到:

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

這將編譯,但它可能不會產生所需的結果。

+0

不完全是答案,但它把我帶到了我正在尋找的東西。基本上,您可以使用fec.toArray()而不是toElements將電氣設備組合成一個數組;然後迭代。謝謝您的幫助。 – CornCat 2010-09-14 00:28:29