public static double SolidVolume(this IOpening opening) { if (opening is BH.oM.Physical.Elements.Void) { Engine.Reflection.Compute.RecordError("Voids contain no solid volume. Try querying the desired value another way."); return(0); } double area = opening.IArea(); double thickness = 0; if (opening is Window) { thickness = (opening as Window).Construction.IThickness(); } else if (opening is Door) { thickness = (opening as Door).Construction.IThickness(); } double solidVolume = area * thickness; if (solidVolume <= 0) { Engine.Reflection.Compute.RecordError("Solid volume cannot be calculated for element of type :" + opening.GetType() + ". Returning zero volume."); return(0); } return(solidVolume); }
public static MaterialComposition MaterialComposition(this IOpening opening) { MaterialComposition materialComposition = null; if (opening is Window) { if ((opening as Window).Construction == null) { Engine.Reflection.Compute.RecordError("The IOpening MaterialComposition could not be calculated as no IConstruction has been assigned."); return(null); } materialComposition = (opening as Window).Construction.IMaterialComposition(); } if (opening is Door) { if ((opening as Door).Construction == null) { Engine.Reflection.Compute.RecordError("The IOpening MaterialComposition could not be calculated as no IConstruction has been assigned."); return(null); } materialComposition = (opening as Door).Construction.IMaterialComposition(); } if (opening is BH.oM.Physical.Elements.Void) { Engine.Reflection.Compute.RecordError("Void's do not support constructions and therefore, contain no material composition. Returning null."); return(null); } return(materialComposition); }
public static IOpening ToSAM_Opening(this EnergyAnalysisOpening energyAnalysisOpening, ConvertSettings convertSettings) { if (energyAnalysisOpening == null) { return(null); } IOpening result = convertSettings?.GetObject <IOpening>(energyAnalysisOpening.Id); if (result != null) { return(result); } Polygon3D polygon3D = energyAnalysisOpening.GetPolyloop().ToSAM(); if (polygon3D == null) { return(null); } FamilyInstance familyInstance = Core.Revit.Query.Element(energyAnalysisOpening) as FamilyInstance; if (familyInstance == null) { return(null); } if (Core.Revit.Query.Simplified(familyInstance)) { result = Core.Revit.Query.IJSAMObjects <IOpening>(familyInstance)?.FirstOrDefault(); if (result != null) { return(result); } } OpeningType openingType = ToSAM_OpeningType(familyInstance.Symbol, convertSettings); Point3D point3D_Location = Geometry.Revit.Query.LocationPoint3D(familyInstance); if (point3D_Location == null) { return(null); } Face3D face3D = new Face3D(Geometry.Spatial.Create.IClosedPlanar3D(polygon3D, point3D_Location)); if (face3D == null) { return(null); } result = Analytical.Create.Opening(openingType, face3D); result.UpdateParameterSets(familyInstance); convertSettings?.Add(energyAnalysisOpening.Id, result); return(result); }
public static IOpening <TEdge> SetOutlineElements1D <TEdge>(this IOpening <TEdge> opening, IEnumerable <IElement1D> edges) where TEdge : IEdge { IOpening <TEdge> o = opening.ShallowClone(); o.Edges = ConvertToEdges <TEdge>(edges); return(o); }
public static IOpening SetOutlineElements1D(this IOpening opening, List <IElement1D> outlineElements1D) { IOpening clone = (IOpening)opening.GetShallowClone(); ICurve outline = Engine.Geometry.Compute.IJoin(outlineElements1D.Select(x => x.IGeometry()).ToList()).Single(); clone.Location = Engine.Geometry.Create.PlanarSurface(outline); return(clone); }
public static PolyCurve Geometry <TEdge>(this IOpening <TEdge> opening) where TEdge : IEdge { return(new PolyCurve { Curves = opening?.Edges?.Select(x => x?.Curve).ToList() }); }
public static bool HasMergeablePropertiesWith(this IOpening element, IOpening other) { if (element == null || other == null) { return(false); //If either is null, then it can probably can't have its properties merged } return(element.GetType() == other.GetType()); }
public static window ToT3D(this IOpening opening, Building building) { if (opening == null) { return(null); } uint colour; if (!Core.Query.TryGetValue(opening, "Color", out colour)) { colour = Core.Convert.ToUint(Color.Black); } Geometry.Spatial.BoundingBox3D boundingBox3D = opening.Face3D?.GetBoundingBox(); double width = double.NaN; if (!Core.Query.TryGetValue(opening, "Width", out width)) { if (boundingBox3D == null) { return(null); } } double height = double.NaN; double level = double.NaN; throw new System.NotImplementedException(); // double height = double.NaN; //double level = double.NaN; //PlanarBoundary3D planarBoundary3D = opening.PlanarBoundary3D; //if(planarBoundary3D == null) //{ // if (!Core.Query.TryGetValue(opening, "Width", out width)) // return null; // if (!Core.Query.TryGetValue(opening, "Height", out height)) // return null; // if (!Core.Query.TryGetValue(opening, "Level", out level)) // return null; //} //else //{ // width = planarBoundary3D.Width(); // height = planarBoundary3D.Height(); // level = Analytical.Query.MinElevation(planarBoundary3D); //} window result = building.AddWindow(opening.Name, Query.OpeningType(opening), colour, height, width, level); return(result); }
public static IOpening Transform(Transform transform, IOpening opening) { if (transform == null || opening == null) { return(null); } return(Analytical.Create.Opening(opening.Guid, opening.Type(), Geometry.Revit.Query.Transform(transform, opening.Face3D))); }
public static List <Polyline> ExternalPolyline(IOpening physicalOpening) { if (physicalOpening == null) { BH.Engine.Reflection.Compute.RecordError("Cannot query the external polyline of a null opening."); return(new List <Polyline>()); } return(physicalOpening.Location.IExternalEdges().Select(x => x.ICollapseToPolyline(Tolerance.Angle)).ToList()); }
public static List <IElement1D> OutlineElements1D(this IOpening opening) { PlanarSurface pSurface = opening.Location as PlanarSurface; if (pSurface == null) { Engine.Reflection.Compute.RecordError("Not implemented for non-PlanarSurfaces"); return(null); } return(pSurface.ExternalBoundary.ISubParts().ToList <IElement1D>()); }
public static IOpening Transform(this IOpening opening, TransformMatrix transform, double tolerance = Tolerance.Distance) { if (!transform.IsRigidTransformation(tolerance)) { BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported."); return(null); } IOpening result = opening.ShallowClone(); result.Location = result.Location?.ITransform(transform); return(result); }
public static IOpening SetOutlineElements1D(this IOpening opening, List <IElement1D> outlineElements1D) { if (opening == null) { BH.Engine.Reflection.Compute.RecordError("Cannot set the outline 1D elements of a null opening."); return(null); } IOpening clone = opening.ShallowClone(); ICurve outline = Engine.Geometry.Compute.IJoin(outlineElements1D.Select(x => x.IGeometry()).ToList()).Single(); clone.Location = Engine.Geometry.Create.PlanarSurface(outline); return(clone); }
public static List <IPartition> ToSAM_Partitions(this HostObject hostObject, ConvertSettings convertSettings) { if (hostObject == null) { return(null); } List <IPartition> result = convertSettings?.GetObjects <IPartition>(hostObject.Id); if (result != null) { return(result); } ElementId elementId_Type = hostObject.GetTypeId(); if (elementId_Type == null || elementId_Type == ElementId.InvalidElementId) { return(null); } HostPartitionType hostPartitionType = ((HostObjAttributes)hostObject.Document.GetElement(elementId_Type)).ToSAM_HostPartitionType(convertSettings); if (hostPartitionType == null) { return(null); } 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; } } result = new List <IPartition>(); foreach (Face3D face3D in face3Ds) { if (face3D == null) { continue; } IHostPartition hostPartition = Analytical.Create.HostPartition(face3D, hostPartitionType); hostPartition.UpdateParameterSets(hostObject); 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; } IOpening opening = ToSAM_Opening((FamilyInstance)element, convertSettings); if (opening != null) { opening = Analytical.Query.Project(hostPartition, opening); hostPartition.AddOpening(opening); } } } result.Add(hostPartition); } convertSettings?.Add(hostObject.Id, result); return(result); }
public static bool HasMergeablePropertiesWith(this IOpening element, IOpening other) { return(element.GetType() == other.GetType()); }
public static IElement1D NewElement1D(this IOpening surface, ICurve curve) { return(curve.IClone()); }
public static double Mass(this IOpening opening) { MaterialComposition mat = opening.IMaterialComposition(); return(opening.SolidVolume() * mat.Materials.Zip(mat.Ratios, (m, r) => r * m.Density()).Sum()); }
public static List <Polyline> InternalPolyline(IOpening physicalOpening) { return(physicalOpening.Location.IInternalEdges().Select(x => x.ICollapseToPolyline(Tolerance.Angle)).ToList()); }
public static int OpeningType(this IOpening opening) { throw new NotImplementedException(); return(1); }
public static List <IAnalyticalObject> ToSAM_AnalyticalObject(this Element element, ConvertSettings convertSettings) { List <IAnalyticalObject> result = null; if (element is WallSweep) { List <IPartition> partitions = ToSAM_Partitions((WallSweep)element, convertSettings); if (partitions != null) { result = partitions.ConvertAll(x => x as IAnalyticalObject); } } else if (element is HostObject) { List <IPartition> partitions = ToSAM_Partitions((HostObject)element, convertSettings); if (partitions != null) { result = partitions.ConvertAll(x => x as IAnalyticalObject); } } else if (element is HostObjAttributes) { HostPartitionType hostPartitionType = ToSAM_HostPartitionType((HostObjAttributes)element, convertSettings); if (hostPartitionType != null) { result = new List <IAnalyticalObject>() { hostPartitionType } } ; } else if (element is SpatialElement) { Space space = ToSAM((SpatialElement)element, convertSettings); if (space != null) { result = new List <IAnalyticalObject>() { space } } ; } else if (element is FamilyInstance) { FamilyInstance familyInstance = (FamilyInstance)element; if (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows || element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors) { IOpening opening = ToSAM_Opening(familyInstance, convertSettings); if (opening != null) { result = new List <IAnalyticalObject>() { opening } } ; } else { //result = familyInstance.ToSAM_Panels(convertSettings); } } else if (element is FamilySymbol) { if (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows || element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors) { OpeningType openingType = ToSAM_OpeningType((FamilySymbol)element, convertSettings); if (openingType != null) { result = new List <IAnalyticalObject>() { openingType } } ; } } else if (element is ModelCurve) { //if (element.Category != null && (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_MEPSpaceSeparationLines || element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_RoomSeparationLines)) //{ // List<Panel> panels = ToSAM_Panels((ModelCurve)element, convertSettings); // if (panels != null) // result = panels.ConvertAll(x => x as Core.SAMObject); //} } return(result); }
/******************************************************/ /**** IOpening Methods ****/ /******************************************************/ private static MaterialComposition IMaterialComposition(this IOpening prop) { return(MaterialComposition(prop as dynamic)); }
public static IOpening ToSAM_Opening(this FamilyInstance familyInstance, ConvertSettings convertSettings) { if (familyInstance == null) { return(null); } IOpening result = convertSettings?.GetObject <IOpening>(familyInstance.Id); if (result != null) { return(result); } if (Core.Revit.Query.Simplified(familyInstance)) { result = Core.Revit.Query.IJSAMObjects <IOpening>(familyInstance)?.FirstOrDefault(); if (result != null) { convertSettings?.Add(familyInstance.Id, result); return(result); } } Point3D point3D_Location = Geometry.Revit.Query.LocationPoint3D(familyInstance); if (point3D_Location == null) { List <Solid> solids = Core.Revit.Query.Solids(familyInstance, new Options()); solids?.RemoveAll(x => x.Volume == 0); if (solids == null || solids.Count == 0) { return(null); } if (solids.Count > 1) { solids.Sort((x, y) => y.Volume.CompareTo(x.Volume)); } point3D_Location = solids[0].ComputeCentroid()?.ToSAM(); } if (point3D_Location == null) { return(null); } OpeningType openingType = ToSAM_OpeningType(familyInstance.Symbol, convertSettings); if (openingType == null) { return(null); } BuiltInCategory builtInCategory_Host = BuiltInCategory.INVALID; HostObject hostObject = familyInstance.Host as HostObject; if (hostObject != null) { builtInCategory_Host = (BuiltInCategory)hostObject.Category.Id.IntegerValue; } Vector3D axisX = null; Vector3D normal = null; Vector3D axisY = null; if (builtInCategory_Host == BuiltInCategory.OST_Roofs) { axisX = familyInstance.HandOrientation.ToSAM_Vector3D(false); axisY = familyInstance.FacingOrientation.ToSAM_Vector3D(false); normal = Geometry.Spatial.Query.AxisY(axisY, axisX); } else { axisX = familyInstance.HandOrientation.ToSAM_Vector3D(false); normal = familyInstance.FacingOrientation.ToSAM_Vector3D(false); axisY = Geometry.Spatial.Query.AxisY(normal, axisX); } Geometry.Spatial.Plane plane = Geometry.Spatial.Create.Plane(point3D_Location, axisX, axisY); if (!plane.Normal.SameHalf(normal)) { plane.FlipZ(false); } List <Face3D> face3Ds = Geometry.Revit.Convert.ToSAM_Geometries <Face3D>(familyInstance); if (face3Ds == null || face3Ds.Count == 0) { return(null); } List <Point2D> point2Ds = new List <Point2D>(); foreach (Face3D face3D_Temp in face3Ds) { IClosedPlanar3D closedPlanar3D = face3D_Temp.GetExternalEdge3D(); if (closedPlanar3D is ICurvable3D) { List <ICurve3D> curve3Ds = ((ICurvable3D)closedPlanar3D).GetCurves(); foreach (ICurve3D curve3D in curve3Ds) { ICurve3D curve3D_Temp = plane.Project(curve3D); point2Ds.Add(plane.Convert(curve3D_Temp.GetStart())); } } } if (point2Ds == null || point2Ds.Count == 0) { return(null); } Rectangle2D rectangle2D = Geometry.Planar.Create.Rectangle2D(point2Ds); result = Analytical.Create.Opening(openingType, new Face3D(plane, rectangle2D)); result.UpdateParameterSets(familyInstance); convertSettings?.Add(familyInstance.Id, result); return(result); }
public static HoneybeeSchema.Door ToLadybugTools(this IOpening opening, BuildingModel buildingModel, Space space) { if (opening == null || buildingModel == null) { return(null); } OpeningType openingType = opening.Type(); if (openingType == null) { return(null); } //Opaque Windows to be replaced by Doors if (opening is Window && buildingModel.GetMaterialType(openingType.PaneMaterialLayers) != MaterialType.Opaque) { return(null); } IHostPartition hostPartition = buildingModel.GetHostPartition(opening); int index = -1; int index_Adjacent = -1; List <Space> spaces = null; if (hostPartition != null) { spaces = buildingModel.GetSpaces(hostPartition); if (spaces != null && spaces.Count != 0) { index = spaces.FindIndex(x => x.Guid == space.Guid); index = buildingModel.UniqueIndex(spaces[index]); index_Adjacent = spaces.FindIndex(x => x.Guid != space.Guid); index_Adjacent = buildingModel.UniqueIndex(spaces[index_Adjacent]); } } HoneybeeSchema.AnyOf <Outdoors, Surface> anyOf = null; if (index == -1 || index_Adjacent == -1) { anyOf = new Outdoors(); } else { bool reversed = index_Adjacent < index; List <string> uniqueNames = new List <string>(); uniqueNames.Add(Core.LadybugTools.Query.UniqueName(opening as SAMObject, index_Adjacent)); uniqueNames.Add(Query.UniqueName(hostPartition, index_Adjacent)); uniqueNames.Add(Query.UniqueName(spaces[index_Adjacent])); anyOf = new Surface(uniqueNames); } Face3D face3D = Geometry.LadybugTools.Convert.ToLadybugTools(opening); DoorEnergyPropertiesAbridged doorEnergyPropertiesAbridged = new DoorEnergyPropertiesAbridged(construction: Query.UniqueName(opening.Type(), !(index_Adjacent != -1 && index <= index_Adjacent))); return(new HoneybeeSchema.Door( identifier: Core.LadybugTools.Query.UniqueName(opening as SAMObject, index), geometry: face3D, boundaryCondition: anyOf, properties: new DoorPropertiesAbridged(doorEnergyPropertiesAbridged), displayName: opening.Name)); }
public static List <IElement1D> OutlineElements1D <TEdge>(this IOpening <TEdge> opening) where TEdge : IEdge { return(opening.Edges.Cast <IElement1D>().ToList()); }