Message 1 of 2
Get Zones (and their Spaces) by Level
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hallo Everyone,
for some reason I am having a hard time with getting my Zones in a Project sorted by the level they are on.
I tried in two different ways, but none work.
I would be very happy if you could help me out.
Here are the two variations that I tried:
public static BindingList<ClassZone> getZones(Level floor)
{
BindingList<ClassZone> czones = new BindingList<ClassZone>();
try
{
//Variant Number 1:
// Find all Zone elements
ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_HVAC_Zones);
// Apply the filter to the elements in the active document
FilteredElementCollector collector = new FilteredElementCollector(_doc);
IList<Element> zones = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();
//Variant Number 2:
IEnumerable<Element> zones = new FilteredElementCollector(_doc) //search only in this level
.OfClass(typeof(Element)).Where(zone => zone.GetType() == typeof(Autodesk.Revit.DB.Mechanical.Zone)).Cast<Element>().Where(o => o.LevelId == floor.Id);
foreach (Element z in zones)
{
if (z.LevelId == floor.LevelId)
{
ClassZone czone = parseZone((Zone)z);
if (czone != null)
{
czones.Add(czone);
}
else
{
TaskDialog.Show("Zonen Fehler!!", "The Number of Zones on the Floor = 0");
}
}
}
}
catch(Exception e)
{
TaskDialog.Show("Fehler bei den Zones", e, TaskDialogCommonButtons.Ok);
}
return czones;
}