public static Panel ToSAM(this gbXMLSerializer.Surface surface, double tolerance = Tolerance.MicroDistance) { if (surface == null) { return(null); } Polygon3D polygon3D = surface.PlanarGeometry.ToSAM(tolerance); if (polygon3D == null) { return(null); } PanelType panelType = Query.PanelType(surface.surfaceType); Construction construction = new Construction(surface.Name); Panel result = new Panel(construction, panelType, new Face3D(polygon3D)); Opening[] openings = surface.Opening; if (openings != null) { foreach (Opening opening in openings) { Aperture aperture = opening.ToSAM(tolerance); if (aperture != null) { result.AddAperture(aperture); } } } return(result); }
public static Panel Transform(this Transform transform, Panel panel) { if (transform == null || panel == null) { return(null); } if (transform.IsIdentity) { return(Analytical.Create.Panel(panel)); } List <Aperture> apertures = panel.Apertures; if (apertures != null) { for (int i = 0; i < apertures.Count; i++) { apertures[i] = Transform(transform, apertures[i]); } } Panel result = Analytical.Create.Panel(panel.Guid, panel, Transform(transform, panel.PlanarBoundary3D)); if (result == null) { return(result); } result.RemoveApertures(); if (apertures != null) { apertures.ForEach(x => result.AddAperture(x)); } return(result); }
public static List <Panel> ToSAM(this HostObject hostObject, ConvertSettings convertSettings) { if (hostObject == null || !hostObject.IsValidObject) { return(null); } if (hostObject is WallSweep) { return(((WallSweep)hostObject).ToSAM_Panels(convertSettings)); } List <Panel> result = convertSettings?.GetObjects <Panel>(hostObject.Id); if (result != null) { return(result); } ElementId elementId_Type = hostObject.GetTypeId(); if (elementId_Type == null || elementId_Type == ElementId.InvalidElementId) { return(null); } Document document = hostObject.Document; if (document == null) { return(null); } result = new List <Panel>(); PanelType panelType = Query.PanelType(hostObject); Construction construction = ((HostObjAttributes)document.GetElement(elementId_Type)).ToSAM(convertSettings); if (construction == null) { construction = Analytical.Query.DefaultConstruction(panelType); //Default Construction } PanelType panelType_Temp = Query.PanelType(construction); if (panelType_Temp != PanelType.Undefined) { panelType = panelType_Temp; } List <Face3D> face3Ds = hostObject.Profiles(); if (face3Ds == null || face3Ds.Count == 0) { return(null); } LogicalOrFilter logicalOrFilter = new LogicalOrFilter(new List <ElementFilter>() { new ElementCategoryFilter(BuiltInCategory.OST_Windows), new ElementCategoryFilter(BuiltInCategory.OST_Doors) }); #if Revit2017 IEnumerable <ElementId> elementIds = null; #else IEnumerable <ElementId> elementIds = hostObject.GetDependentElements(logicalOrFilter); #endif if (hostObject is Autodesk.Revit.DB.Wall || hostObject is CurtainSystem) { List <Autodesk.Revit.DB.Panel> panels = Core.Revit.Query.Panels(hostObject as dynamic); if (panels != null && panels.Count > 0) { List <ElementId> elementIds_Temp = panels.ConvertAll(x => x.Id); if (elementIds != null && elementIds.Count() > 0) { elementIds_Temp.AddRange(elementIds); } elementIds = elementIds_Temp; } } List <Aperture> apertures = new List <Aperture>(); if (elementIds != null && elementIds.Count() > 0) { foreach (ElementId elementId in elementIds) { FamilyInstance familyInstance = document.GetElement(elementId) as FamilyInstance; if (familyInstance == null) { continue; } List <Aperture> apertures_Temp = ToSAM_Apertures(familyInstance, convertSettings); if (apertures_Temp == null) { continue; } apertures.AddRange(apertures_Temp); } } foreach (Face3D face3D in face3Ds) { if (face3D == null) { continue; } //Panel panel = Analytical.Create.Panel(construction, panelType, face3D.Reduce(0.2)); Double check why Reduce have been used turn off on 27.10.2021 when mesh roof in sam teplate gave gap Panel panel = Analytical.Create.Panel(construction, panelType, face3D); panel.UpdateParameterSets(hostObject, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap)); foreach (Aperture aperture in apertures) { panel.AddAperture(aperture); } result.Add(panel); } convertSettings?.Add(hostObject.Id, result); //Handling WallSweeps //if(hostObject is Wall) //{ // elementIds = hostObject.GetDependentElements(new ElementCategoryFilter(BuiltInCategory.OST_Cornices)); // if (elementIds != null && elementIds.Count() != 0) // { // //Fix it // foreach (ElementId elementId in elementIds) // { // WallSweep wallSweep = document.GetElement(elementId) as WallSweep; // if (wallSweep == null) // { // continue; // } // List<Panel> panels_WallSweep = wallSweep.ToSAM_Panels(convertSettings); // if (panels_WallSweep == null || panels_WallSweep.Count == 0) // { // continue; // } // result.AddRange(panels_WallSweep); // } // } //} return(result); }
public static List <Panel> ToSAM(this HostObject hostObject, ConvertSettings convertSettings) { if (hostObject == null || !hostObject.IsValidObject) { return(null); } List <Panel> result = convertSettings?.GetObjects <Panel>(hostObject.Id); if (result != null) { return(result); } ElementId elementId_Type = hostObject.GetTypeId(); if (elementId_Type == null || elementId_Type == ElementId.InvalidElementId) { return(null); } result = new List <Panel>(); PanelType panelType = Query.PanelType(hostObject); Construction construction = ((HostObjAttributes)hostObject.Document.GetElement(elementId_Type)).ToSAM(convertSettings); if (construction == null) { construction = Analytical.Query.DefaultConstruction(panelType); //Default Construction } PanelType panelType_Temp = Query.PanelType(construction); if (panelType_Temp != PanelType.Undefined) { panelType = panelType_Temp; } List <Geometry.Spatial.Face3D> face3Ds = hostObject.Profiles(); if (face3Ds == null || face3Ds.Count == 0) { return(null); } LogicalOrFilter logicalOrFilter = new LogicalOrFilter(new List <ElementFilter>() { new ElementCategoryFilter(BuiltInCategory.OST_Windows), new ElementCategoryFilter(BuiltInCategory.OST_Doors) }); IEnumerable <ElementId> elementIds = hostObject.GetDependentElements(logicalOrFilter); if (hostObject is Wall) { List <Autodesk.Revit.DB.Panel> panels = Create.Panels((Wall)hostObject, convertSettings); if (panels != null && panels.Count > 0) { List <ElementId> elementIds_Temp = panels.ConvertAll(x => x.Id); if (elementIds != null && elementIds.Count() > 0) { elementIds_Temp.AddRange(elementIds); } elementIds = elementIds_Temp; } } foreach (Geometry.Spatial.Face3D face3D in face3Ds) { if (face3D == null) { continue; } Panel panel = new Panel(construction, panelType, face3D); panel.UpdateParameterSets(hostObject, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap)); if (elementIds != null && elementIds.Count() > 0) { foreach (ElementId elementId in elementIds) { Element element = hostObject.Document.GetElement(elementId); if (element == null) { continue; } if (!(element is FamilyInstance)) { continue; } Aperture aperture = ToSAM_Aperture((FamilyInstance)element, convertSettings); panel.AddAperture(aperture); } } result.Add(panel); } convertSettings?.Add(hostObject.Id, result); return(result); }
public static bool UpdateConstructions( this Document document, IEnumerable <Panel> panels, Core.DelimitedFileTable delimitedFileTable, ConstructionLibrary constructionLibrary, ApertureConstructionLibrary apertureConstructionLibrary, out List <Panel> panels_Result, out List <Aperture> apertures_Result, out List <ElementType> elementTypes_Panels, out List <ElementType> elementTypes_Apertures, out ConstructionLibrary constructionLibrary_Result, out ApertureConstructionLibrary apertureConstructionLibrary_Result, string sourceColumnName, string destinationColumnName, string templateColumnName, string typeColumnName, string thicknessColumnName = null) { panels_Result = null; apertures_Result = null; elementTypes_Panels = null; elementTypes_Apertures = null; constructionLibrary_Result = null; apertureConstructionLibrary_Result = null; if (document == null || panels == null || delimitedFileTable == null || constructionLibrary == null || apertureConstructionLibrary == null) { return(false); } int index_Source = delimitedFileTable.GetColumnIndex(sourceColumnName); if (index_Source == -1) { return(false); } int index_Template = delimitedFileTable.GetColumnIndex(templateColumnName); if (index_Template == -1) { return(false); } int index_Destination = delimitedFileTable.GetColumnIndex(destinationColumnName); if (index_Destination == -1) { return(false); } int index_Type = delimitedFileTable.GetColumnIndex(typeColumnName); if (index_Type == -1) { return(false); } panels_Result = new List <Panel>(); apertures_Result = new List <Aperture>(); elementTypes_Panels = new List <ElementType>(); elementTypes_Apertures = new List <ElementType>(); int index_Thickness = delimitedFileTable.GetColumnIndex(thicknessColumnName); constructionLibrary_Result = new ConstructionLibrary(constructionLibrary.Name); apertureConstructionLibrary_Result = new ApertureConstructionLibrary(apertureConstructionLibrary.Name); Core.Revit.ConvertSettings convertSettings = Core.Revit.Query.ConvertSettings(); foreach (Panel panel in panels) { Construction construction = panel?.Construction; if (construction == null) { continue; } string name = construction.Name; if (name == null) { continue; } string name_Destination = null; string name_Template = null; string name_Source = null; PanelType panelType = PanelType.Undefined; double thickness = double.NaN; for (int i = 0; i < delimitedFileTable.RowCount; i++) { string typeName = null; if (delimitedFileTable.TryConvert(i, index_Type, out typeName)) { ApertureType apertureType = Analytical.Query.ApertureType(typeName); if (apertureType != ApertureType.Undefined) { continue; } panelType = Analytical.Query.PanelType(typeName as object); } if (!delimitedFileTable.TryConvert(i, index_Source, out name_Source)) { continue; } if (!name.Equals(name_Source)) { continue; } if (!delimitedFileTable.TryConvert(i, index_Destination, out name_Destination)) { name_Destination = null; continue; } if (!delimitedFileTable.TryConvert(i, index_Template, out name_Template)) { name_Template = null; } if (index_Thickness != -1) { if (!delimitedFileTable.TryConvert(i, index_Thickness, out thickness)) { thickness = double.NaN; } } break; } if (string.IsNullOrWhiteSpace(name_Destination)) { name_Destination = name_Template; } if (string.IsNullOrWhiteSpace(name_Destination)) { continue; } if (panelType == PanelType.Undefined) { panelType = panel.PanelType; } Construction construction_New = constructionLibrary_Result.GetConstructions(name_Destination)?.FirstOrDefault(); if (construction_New == null) { Construction construction_Temp = constructionLibrary.GetConstructions(name_Template)?.FirstOrDefault(); if (construction_Temp == null) { continue; } if (name_Destination.Equals(name_Template)) { construction_New = construction_Temp; } else { construction_New = new Construction(construction_Temp, name_Destination); } construction_New.SetValue(ConstructionParameter.Description, construction.Name); construction_New.RemoveValue(ConstructionParameter.DefaultPanelType); if (!double.IsNaN(thickness)) { construction_New.SetValue(ConstructionParameter.DefaultThickness, thickness); } constructionLibrary_Result.Add(construction_New); } HostObjAttributes hostObjAttributes = Convert.ToRevit(construction_New, document, panelType, panel.Normal, convertSettings); if (hostObjAttributes == null) { if (string.IsNullOrWhiteSpace(name_Template)) { Construction construction_Default = Analytical.Query.DefaultConstruction(panelType); if (construction_Default != null) { name_Template = construction_Default.Name; } } if (string.IsNullOrWhiteSpace(name_Template)) { continue; } hostObjAttributes = DuplicateByType(document, name_Template, panelType, construction_New) as HostObjAttributes; } Construction construction_New_Temp = new Construction(hostObjAttributes.ToSAM(new Core.Revit.ConvertSettings(false, true, false)), construction_New.Guid); construction_New_Temp = new Construction(construction_New_Temp, construction_New.ConstructionLayers); constructionLibrary_Result.Add(construction_New_Temp); Panel panel_New = Analytical.Create.Panel(panel, construction_New_Temp); if (panel_New.PanelType != panelType) { panel_New = Analytical.Create.Panel(panel_New, panelType); } List <Aperture> apertures = panel_New.Apertures; if (apertures != null && apertures.Count != 0) { foreach (Aperture aperture in apertures) { panel_New.RemoveAperture(aperture.Guid); ApertureConstruction apertureConstruction = aperture?.ApertureConstruction; if (apertureConstruction == null) { continue; } name = apertureConstruction.Name; if (name == null) { continue; } name_Destination = null; name_Template = null; name_Source = null; ApertureType apertureType = ApertureType.Undefined; for (int i = 0; i < delimitedFileTable.RowCount; i++) { string typeName = null; if (!delimitedFileTable.TryGetValue(i, index_Type, out typeName) || string.IsNullOrWhiteSpace(typeName)) { continue; } apertureType = Analytical.Query.ApertureType(typeName); if (apertureType == ApertureType.Undefined) { if (typeName.Trim().Equals("Curtain Panels")) { apertureType = ApertureType.Window; } } if (apertureType == ApertureType.Undefined) { continue; } if (!delimitedFileTable.TryGetValue(i, index_Source, out name_Source) || string.IsNullOrWhiteSpace(name_Source)) { continue; } if (!name.Equals(name_Source)) { continue; } if (!delimitedFileTable.TryGetValue(i, index_Destination, out name_Destination)) { name_Destination = null; continue; } if (!delimitedFileTable.TryGetValue(i, index_Template, out name_Template)) { name_Template = null; } break; } if (string.IsNullOrWhiteSpace(name_Destination)) { name_Destination = name_Template; } if (string.IsNullOrWhiteSpace(name_Destination)) { continue; } if (apertureType == ApertureType.Undefined) { continue; } ApertureConstruction apertureConstruction_New = apertureConstructionLibrary_Result.GetApertureConstructions(name_Destination, Core.TextComparisonType.Equals, true, apertureType)?.FirstOrDefault(); if (apertureConstruction_New == null) { ApertureConstruction apertureConstruction_Temp = apertureConstructionLibrary.GetApertureConstructions(name_Template, Core.TextComparisonType.Equals, true, apertureType)?.FirstOrDefault(); if (apertureConstruction_Temp == null) { continue; } if (name_Destination.Equals(name_Template)) { apertureConstruction_New = apertureConstruction_Temp; } else { apertureConstruction_New = new ApertureConstruction(apertureConstruction_Temp, name_Destination); } apertureConstruction_New.SetValue(ApertureConstructionParameter.Description, apertureConstruction.Name); apertureConstructionLibrary_Result.Add(apertureConstruction_New); } FamilySymbol familySymbol = Convert.ToRevit(apertureConstruction_New, document, convertSettings); if (familySymbol == null) { if (string.IsNullOrWhiteSpace(name_Template)) { ApertureConstruction apertureConstruction_Default = Analytical.Query.DefaultApertureConstruction(panelType, apertureType); if (apertureConstruction_Default != null) { name_Template = apertureConstruction_Default.Name; } } if (string.IsNullOrWhiteSpace(name_Template)) { continue; } familySymbol = DuplicateByType(document, name_Template, apertureConstruction_New) as FamilySymbol; } Aperture aperture_New = new Aperture(aperture, apertureConstruction_New); if (panel_New.AddAperture(aperture_New)) { elementTypes_Apertures.Add(familySymbol); apertures_Result.Add(aperture_New); } } } elementTypes_Panels.Add(hostObjAttributes); panels_Result.Add(panel_New); } return(true); }
public static Panel ToSAM(this Face face, IEnumerable <Construction> constructions = null, IEnumerable <ApertureConstruction> apertureConstructions = null) { if (face == null) { return(null); } Geometry.Spatial.Face3D face3D = Geometry.LadybugTools.Convert.ToSAM(face.Geometry); if (face3D == null) { return(null); } PanelType panelType = PanelType.Undefined; PanelGroup panelGroup = face.FaceType.ToSAM(); Construction construction = null; if (constructions != null && face.Properties?.Energy?.Construction != null) { foreach (Construction construction_Temp in constructions) { if (construction_Temp.Name == face.Properties.Energy.Construction) { construction = construction_Temp; break; } } } AnyOf <Ground, Outdoors, Adiabatic, Surface> boundaryCondition = face.BoundaryCondition; if (boundaryCondition.Obj is Ground) { switch (panelGroup) { case PanelGroup.Floor: panelType = PanelType.SlabOnGrade; break; case PanelGroup.Other: panelType = PanelType.Air; break; case PanelGroup.Roof: panelType = PanelType.UndergroundCeiling; break; case PanelGroup.Wall: panelType = PanelType.UndergroundWall; break; } } else if (boundaryCondition.Obj is Adiabatic) { if (panelGroup == PanelGroup.Roof) { panelType = PanelType.Roof; } } else if (boundaryCondition.Obj is Outdoors) { switch (panelGroup) { case PanelGroup.Floor: panelType = PanelType.FloorExposed; break; case PanelGroup.Other: panelType = PanelType.Shade; break; case PanelGroup.Roof: panelType = PanelType.Roof; break; case PanelGroup.Wall: panelType = PanelType.WallExternal; break; } } else if (boundaryCondition.Obj is Surface) { Surface surface = (Surface)boundaryCondition.Obj; switch (panelGroup) { case PanelGroup.Floor: panelType = PanelType.FloorInternal; break; case PanelGroup.Wall: panelType = PanelType.WallInternal; break; } } if (construction == null) { AnyOf <OpaqueConstructionAbridged, WindowConstructionAbridged, ShadeConstruction, AirBoundaryConstructionAbridged> construction_Honeybee = Query.DefaultConstruction(panelType); if (construction_Honeybee != null) { construction = construction_Honeybee.ToSAM_Construction(); } } if (construction == null) { construction = new Construction(face.Identifier); } Panel panel = Create.Panel(construction, panelType, face3D); if (face.Apertures != null) { foreach (HoneybeeSchema.Aperture aperture_HoneybeeSchema in face.Apertures) { Aperture aperture = aperture_HoneybeeSchema?.ToSAM(panelType.Internal(), apertureConstructions); if (aperture != null) { panel.AddAperture(aperture); } } } if (face.Doors != null) { foreach (HoneybeeSchema.Door door in face.Doors) { Aperture aperture = door?.ToSAM(panelType.Internal(), apertureConstructions); if (aperture != null) { panel.AddAperture(aperture); } } } return(panel); }
public static Panel ToSAM(this EnergyAnalysisSurface energyAnalysisSurface, Core.Revit.ConvertSettings convertSettings, Shell shell = null, double silverSpacing = Core.Tolerance.MacroDistance, double tolerance = Core.Tolerance.Distance) { if (energyAnalysisSurface == null) { return(null); } Panel result = convertSettings?.GetObject <Panel>(energyAnalysisSurface.Id); if (result != null) { return(result); } Document document = energyAnalysisSurface.Document; Polygon3D polygon3D = energyAnalysisSurface.GetPolyloop().ToSAM(); if (polygon3D == null) { return(null); } if (shell != null) { Geometry.Spatial.Plane plane = polygon3D.GetPlane(); if (plane != null) { Point3D point3D = polygon3D.InternalPoint3D(); if (point3D != null) { Vector3D normal = shell.Normal(polygon3D.InternalPoint3D(), true, silverSpacing, tolerance); if (!normal.SameHalf(plane.AxisZ)) { plane.FlipZ(); polygon3D = new Polygon3D(plane, polygon3D.GetPoints().ConvertAll(x => plane.Convert(x))); } } } } HostObject hostObject = Core.Revit.Query.Element(document, energyAnalysisSurface.CADObjectUniqueId, energyAnalysisSurface.CADLinkUniqueId) as HostObject; if (hostObject == null) { return(new Panel(null, PanelType.Air, new Face3D(polygon3D))); } ElementId elementId_Type = hostObject.GetTypeId(); if (elementId_Type == null || elementId_Type == ElementId.InvalidElementId) { return(null); } PanelType panelType = Query.PanelType(hostObject); Construction construction = ((HostObjAttributes)hostObject.Document.GetElement(elementId_Type)).ToSAM(convertSettings); if (construction == null) { construction = Analytical.Query.DefaultConstruction(panelType); //Default Construction } PanelType panelType_Temp = Query.PanelType(construction); if (panelType_Temp != PanelType.Undefined) { panelType = panelType_Temp; } Face3D face3D = new Face3D(polygon3D); result = new Panel(construction, panelType, face3D); IEnumerable <EnergyAnalysisOpening> energyAnalysisOpenings = energyAnalysisSurface.GetAnalyticalOpenings(); if (energyAnalysisOpenings != null && energyAnalysisOpenings.Count() != 0) { foreach (EnergyAnalysisOpening energyAnalysisOpening in energyAnalysisOpenings) { Aperture aperture = energyAnalysisOpening.ToSAM(convertSettings); if (aperture != null) { result.AddAperture(aperture); } } } result.UpdateParameterSets(energyAnalysisSurface, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap)); convertSettings?.Add(energyAnalysisSurface.Id, result); return(result); }