Dear @Moustafa_K
I am also trying to retrieve the Rooms by level and so thanks for the code above. However, I am getting the error that
viewId is not a view.
Parameter name: viewId
Any idea how to resolve the issue.
Here is the code:
//Access Revit session
UIDocument UIDoc = commandData.Application.ActiveUIDocument;
//Access Revit Application
Application Iapp = commandData.Application.Application;
//Revit current project
Document Idoc = UIDoc.Document;
MultiValueDictionary<string, double> Idict = new MultiValueDictionary<string, double>();
StringBuilder Istring = new StringBuilder();
ElementId levid = Idoc.ActiveView.GenLevel.Id;
//get all rooms
var Roomsbylevel = new FilteredElementCollector(Idoc, levid) //search only in this level
.OfClass(typeof(SpatialElement)) //get all rooms
.Cast<SpatialElement>() //cast results to SpatialElements
.Where(o => o.LevelId == levid); //search by the above mentioned Level
//now loop through the results
foreach (var objRoom in Roomsbylevel)
{
Parameter SP_ID = objRoom.LookupParameter("H_BA_ID");
Parameter SP_GF = objRoom.LookupParameter("H_BA_Gesamtfläche");
if (null != SP_ID.AsString() && 0.00 < objRoom.Area)
{
Idict.Add(SP_ID.AsString(), objRoom.Area);
}
}