/// <summary> /// Gets Wall Panels from Spatial Element base on its Boundary /// </summary> /// <param name="spatialElement">Revit Spatial Element such as Space or Room</param> /// <param name="elevation_Bottom">Bottom Elevation</param> /// <param name="elevation_Top">Top Elevation</param> /// <param name="convertSettings">Convert Settings</param> /// <param name="spatialElementBoundaryOptions">Revit SpactialElementBoundaryOptions. Center Spatial Element Boundary Location will be used when set to null</param> /// <returns>Wall Panels</returns> public static List <Panel> Panels(this SpatialElement spatialElement, double elevation_Bottom, double elevation_Top, Core.Revit.ConvertSettings convertSettings, SpatialElementBoundaryOptions spatialElementBoundaryOptions = null) { if (spatialElement == null || double.IsNaN(elevation_Top) || double.IsNaN(elevation_Bottom)) { return(null); } if (spatialElementBoundaryOptions == null) { spatialElementBoundaryOptions = new SpatialElementBoundaryOptions(); spatialElementBoundaryOptions.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center; } Document document = spatialElement.Document; Geometry.Spatial.Plane plane = Geometry.Spatial.Plane.WorldXY; Geometry.Spatial.Plane plane_Top = plane.GetMoved(new Geometry.Spatial.Vector3D(0, 0, elevation_Top)) as Geometry.Spatial.Plane; Geometry.Spatial.Plane plane_Bottom = plane.GetMoved(new Geometry.Spatial.Vector3D(0, 0, elevation_Bottom)) as Geometry.Spatial.Plane; List <Panel> panels = new List <Panel>(); IList <IList <BoundarySegment> > boundaries = spatialElement.GetBoundarySegments(spatialElementBoundaryOptions); foreach (IList <BoundarySegment> boundarySegments in boundaries) { if (boundarySegments == null) { continue; } foreach (BoundarySegment boundarySegment in boundarySegments) { if (boundarySegment == null) { continue; } Curve curve = boundarySegment.GetCurve(); if (curve == null) { continue; } HostObject hostObject = null; if (boundarySegment.ElementId != null && boundarySegment.ElementId != ElementId.InvalidElementId) { if (boundarySegment.LinkElementId == null || boundarySegment.LinkElementId == ElementId.InvalidElementId) { hostObject = document.GetElement(boundarySegment.ElementId) as HostObject; } else { RevitLinkInstance revitLinkInstance = document.GetElement(boundarySegment.LinkElementId) as RevitLinkInstance; if (revitLinkInstance != null) { Document document_Linked = revitLinkInstance.GetLinkDocument(); if (document_Linked != null) { hostObject = document_Linked.GetElement(boundarySegment.ElementId) as HostObject; } } } } Panel panel_Temp = null; if (hostObject != null) { List <Panel> panels_Temp = hostObject.ToSAM(convertSettings); if (panels_Temp != null && panels_Temp.Count > 0) { panel_Temp = panels_Temp[0]; } } List <Geometry.Spatial.Segment3D> segment3Ds = Geometry.Revit.Convert.ToSAM_Segment3Ds(curve); if (segment3Ds == null || segment3Ds.Count == 0) { continue; } foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds) { Geometry.Spatial.Segment3D segment3D_Top = Geometry.Spatial.Query.Project(plane_Top, segment3D); Geometry.Spatial.Segment3D segment3D_Bottom = Geometry.Spatial.Query.Project(plane_Bottom, segment3D); Geometry.Spatial.Polygon3D polygon3D = Geometry.Spatial.Create.Polygon3D(new Geometry.Spatial.Point3D[] { segment3D_Top[0], segment3D_Top[1], segment3D_Bottom[1], segment3D_Bottom[0] }); if (polygon3D == null) { continue; } Geometry.Spatial.Face3D face3D = new Geometry.Spatial.Face3D(polygon3D); Panel panel = null; if (panel_Temp != null) { panel = Analytical.Create.Panel(Guid.NewGuid(), panel_Temp, face3D); } if (panel_Temp != null) { Geometry.Spatial.Vector3D normal = polygon3D.GetPlane()?.Normal; PanelType panelType = Analytical.Query.PanelType(normal); Construction construction = Query.DefaultAirConstruction(panelType.PanelGroup()); panel = Analytical.Create.Panel(construction, panelType, face3D); } if (panel != null) { panels.Add(panel); } } } } return(panels); }
public static AdjacencyCluster ToSAM(this TBD.Building building) { if (building == null) { return(null); } AdjacencyCluster adjacencyCluster = new AdjacencyCluster(); Dictionary <string, Construction> dictionary_Construction = new Dictionary <string, Construction>(); foreach (TBD.Construction construction_TBD in building.Constructions()) { Construction construction = construction_TBD.ToSAM(); if (construction == null) { continue; } dictionary_Construction[construction_TBD.GUID] = construction; adjacencyCluster.AddObject(construction); } foreach (TBD.zone zone in building.Zones()) { Space space = zone.ToSAM(out List <InternalCondition> internalConditions); if (space == null) { continue; } adjacencyCluster.AddObject(space); foreach (TBD.IZoneSurface zoneSurface in zone.ZoneSurfaces()) { TBD.buildingElement buildingElement = zoneSurface.buildingElement; TBD.Construction construction_TBD = buildingElement.GetConstruction(); PanelType panelType = Query.PanelType(buildingElement.BEType); Construction construction = null; if (construction_TBD != null) { construction = dictionary_Construction[construction_TBD.GUID]; } foreach (TBD.IRoomSurface roomSurface in zoneSurface.RoomSurfaces()) { Geometry.Spatial.Polygon3D polygon3D = Geometry.Tas.Convert.ToSAM(roomSurface?.GetPerimeter()?.GetFace()); if (polygon3D == null) { continue; } Panel panel = Analytical.Create.Panel(construction, panelType, new Geometry.Spatial.Face3D(polygon3D)); if (panel == null) { continue; } adjacencyCluster.AddObject(panel); adjacencyCluster.AddRelation(panel, space); } } if (internalConditions != null) { foreach (InternalCondition internalCondition in internalConditions) { adjacencyCluster.AddObject(internalCondition); adjacencyCluster.AddRelation(space, internalCondition); } } } return(adjacencyCluster); }