public static List <Zone> Zones(List <IObject> referenceElements, ZoneDimensions zoneDimensions) { List <Zone> zones = new List <Zone>(); foreach (var refElement in referenceElements) { ZoneReferenceElement zoneRefEl = refElement.ToZoneReferenceElement(); if (zoneRefEl.ZoneName != zoneDimensions.ZoneName) { continue; } BoundingBox bb = Query.IElementBoundingBox(zoneRefEl.ReferenceGeometry, zoneDimensions.Width, zoneDimensions.Height, zoneDimensions.Depth); if (bb != null) { Zone zone = new Zone() { ZoneName = zoneRefEl.ZoneName, ClosedVolume = bb }; zones.Add(zone); } } return(zones); }
public static List <Zone> Zones(List <IObject> referenceElements, List <ZoneDimensions> zoneDimensions) { List <Zone> zones = new List <Zone>(); var zone_refElements = referenceElements .Select(refEl => refEl.ToZoneReferenceElement()) .Where(zRefEl => zRefEl != null) .GroupBy(zRefEl => zRefEl.ZoneName) .ToDictionary(g => g.Key, g => g.ToList()); var zone_zoneDims = zoneDimensions .GroupBy(zDim => zDim.ZoneName) .ToDictionary(g => g.Key, g => g.ToList()); var commonZones = zone_refElements.Keys.Intersect(zone_zoneDims.Keys); foreach (string zoneName in commonZones) { if (zone_zoneDims[zoneName].Count() > 1) { BH.Engine.Reflection.Compute.RecordWarning($"Cannot create {zoneName}: more than 1 `{nameof(ZoneDimensions)}` objects specified for it."); continue; } ZoneDimensions zoneDims = zone_zoneDims[zoneName].FirstOrDefault(); if (zoneDims == null) { BH.Engine.Reflection.Compute.RecordWarning($"Cannot create {zoneName}: no valid `{nameof(ZoneDimensions)}` objects found for it."); continue; } List <IObject> refElems = zone_refElements[zoneName].OfType <IObject>().ToList(); zones.AddRange(Create.Zones(refElems, zoneDims)); } return(zones); }