diff --git a/Revit_Core_Engine/Convert/Physical/FromRevit/PadFoundation.cs b/Revit_Core_Engine/Convert/Physical/FromRevit/PadFoundation.cs new file mode 100644 index 000000000..8e90fb388 --- /dev/null +++ b/Revit_Core_Engine/Convert/Physical/FromRevit/PadFoundation.cs @@ -0,0 +1,70 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2026, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using Autodesk.Revit.DB; +using BH.Engine.Adapters.Revit; +using BH.oM.Adapters.Revit.Settings; +using BH.oM.Base; +using BH.oM.Base.Attributes; +using BH.oM.Geometry; +using BH.oM.Physical.Elements; +using System.Collections.Generic; +using System.ComponentModel; + +namespace BH.Revit.Engine.Core +{ + public static partial class Convert + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + [Description("Converts a Revit FamilyInstance to BH.oM.Physical.Elements.PadFoundation.")] + [Input("familyInstance", "Revit FamilyInstance to be converted.")] + [Input("settings", "Revit adapter settings to be used while performing the convert.")] + [Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + [Output("padFoundation", "BH.oM.Physical.Elements.PadFoundation resulting from converting the input Revit FamilyInstance.")] + public static PadFoundation PadFoundationFromRevit(this FamilyInstance familyInstance, RevitSettings settings = null, Dictionary> refObjects = null) + { + settings = settings.DefaultIfNull(); + + PadFoundation padFoundation = refObjects.GetValue(familyInstance.Id); + if (padFoundation != null) + return padFoundation; + + PlanarSurface location = familyInstance.LocationSurfacePadFoundation(settings); + + oM.Physical.Constructions.Construction construction = familyInstance.ConstructionPadFoundation(settings, refObjects); + padFoundation = BH.Engine.Physical.Create.PadFoundation(location, construction, familyInstance.FamilyTypeFullName()); + + //Set identifiers, parameters & custom data + padFoundation.SetIdentifiers(familyInstance); + padFoundation.CopyParameters(familyInstance, settings.MappingSettings); + padFoundation.SetProperties(familyInstance, settings.MappingSettings); + + refObjects.AddOrReplace(familyInstance.Id, padFoundation); + return padFoundation; + } + + /***************************************************/ + } +} \ No newline at end of file diff --git a/Revit_Core_Engine/Modify/SetLocation.cs b/Revit_Core_Engine/Modify/SetLocation.cs index 1fa10dc84..7d23874e7 100644 --- a/Revit_Core_Engine/Modify/SetLocation.cs +++ b/Revit_Core_Engine/Modify/SetLocation.cs @@ -22,6 +22,7 @@ using Autodesk.Revit.DB; using BH.Engine.Geometry; +using BH.Engine.Spatial; using BH.oM.Adapters.Revit.Elements; using BH.oM.Adapters.Revit.Settings; using BH.oM.Base; diff --git a/Revit_Core_Engine/Query/BHoMType.cs b/Revit_Core_Engine/Query/BHoMType.cs index 9f28b534e..c42b3298e 100644 --- a/Revit_Core_Engine/Query/BHoMType.cs +++ b/Revit_Core_Engine/Query/BHoMType.cs @@ -96,8 +96,7 @@ public static Type BHoMType(this FamilyInstance familyInstance, Discipline disci double width = Math.Max(bbox.Max.X - bbox.Min.X, bbox.Max.Y - bbox.Min.Y); double height = bbox.Max.Z - bbox.Min.Z; if (height < width) - //return typeof(BH.oM.Physical.Elements.PadFoundation); - return null; // Temporarily disabled until PadFoundation is properly implemented in the Revit adapter. + return typeof(BH.oM.Physical.Elements.PadFoundation); else if (familyInstance.GetSubComponentIds().Count != 0) //return typeof(BH.oM.Physical.Elements.PileFoundation); return null; // Temporarily disabled until PileFoundation is properly implemented in the Revit adapter. diff --git a/Revit_Core_Engine/Query/BuiltInCategories.cs b/Revit_Core_Engine/Query/BuiltInCategories.cs index 53f726c67..8386e7406 100644 --- a/Revit_Core_Engine/Query/BuiltInCategories.cs +++ b/Revit_Core_Engine/Query/BuiltInCategories.cs @@ -118,6 +118,12 @@ public static HashSet BuiltInCategories(this Type bHoMType) Autodesk.Revit.DB.BuiltInCategory.OST_StructuralFoundation } }, + { + typeof (BH.oM.Physical.Elements.PadFoundation), new BuiltInCategory[] + { + Autodesk.Revit.DB.BuiltInCategory.OST_StructuralFoundation, + } + }, { typeof (Column), new BuiltInCategory[] { diff --git a/Revit_Core_Engine/Query/Construction.cs b/Revit_Core_Engine/Query/Construction.cs index ca1c15048..4dcf793da 100644 --- a/Revit_Core_Engine/Query/Construction.cs +++ b/Revit_Core_Engine/Query/Construction.cs @@ -22,9 +22,13 @@ using Autodesk.Revit.DB; using Autodesk.Revit.DB.Analysis; +using BH.Engine.Adapters.Revit; +using BH.Engine.Base; using BH.oM.Adapters.Revit.Settings; -using BH.oM.Environment.MaterialFragments; +using BH.oM.Base; using BH.oM.Base.Attributes; +using BH.oM.Environment.MaterialFragments; +using System.Collections.Generic; using System.ComponentModel; namespace BH.Revit.Engine.Core @@ -56,6 +60,52 @@ public static oM.Physical.Constructions.Construction Construction(this EnergyAna return construction; } + /***************************************************/ + + [Description("Extracts the construction of the given Revit FamilyInstance.")] + [Input("familyInstance", "Revit FamilyInstance to extract the construction from.")] + [Input("settings", "Revit adapter settings to be used while performing the query.")] + [Output("construction", "Construction of the input Revit FamilyInstance.")] + public static oM.Physical.Constructions.Construction Construction(this FamilyInstance familyInstance, RevitSettings settings = null, Dictionary> refObjects = null) + { + if (familyInstance == null) + return null; + + if (familyInstance.Category.Id.Value() == (int)Autodesk.Revit.DB.BuiltInCategory.OST_StructuralFoundation) + return familyInstance.ConstructionPadFoundation(settings, refObjects); + else + return familyInstance.Symbol.ConstructionFromRevit(settings, refObjects); + } + + /***************************************************/ + + [Description("Extracts the construction of the given Revit pad foundation.")] + [Input("familyInstance", "Revit pad foundation to extract the construction from.")] + [Input("settings", "Revit adapter settings to be used while performing the query.")] + [Output("construction", "Construction of the input Revit pad foundation.")] + public static oM.Physical.Constructions.Construction ConstructionPadFoundation(this FamilyInstance familyInstance, RevitSettings settings = null, Dictionary> refObjects = null) + { + settings = settings.DefaultIfNull(); + + FamilySymbol familySymbol = familyInstance?.Symbol; + if (familySymbol == null) + return null; + + oM.Physical.Constructions.Construction construction = refObjects.GetValue(familyInstance.Id); + if (construction != null) + return construction; + + construction = familySymbol.ConstructionFromRevit(settings, refObjects); + construction = construction.DeepClone(); + + BoundingBoxXYZ bbox = familyInstance.get_BoundingBox(null); + double thickness = (bbox.Max.Z - bbox.Min.Z).ToSI(SpecTypeId.Length); + + BH.oM.Physical.Materials.Material material = familyInstance.StructuralMaterial(settings, refObjects); + construction.Layers.Add(new oM.Physical.Constructions.Layer { Name = construction.Name, Material = material, Thickness = thickness }); + return construction; + } + /***************************************************/ /**** Private methods ****/ diff --git a/Revit_Core_Engine/Query/FramingElementProperty.cs b/Revit_Core_Engine/Query/FramingElementProperty.cs index 7a421f47c..742c07c5d 100644 --- a/Revit_Core_Engine/Query/FramingElementProperty.cs +++ b/Revit_Core_Engine/Query/FramingElementProperty.cs @@ -54,7 +54,7 @@ public static IFramingElementProperty FramingElementProperty(this FamilyInstance return framingProperty; // Convert the material to BHoM - BH.oM.Physical.Materials.Material material = familyInstance.FramingMaterial(settings, refObjects); + BH.oM.Physical.Materials.Material material = familyInstance.StructuralMaterial(settings, refObjects); // Convert the profile to BHoM and mirror it if needed IProfile profile = familyInstance.Symbol.ProfileFromRevit(settings, refObjects); @@ -111,7 +111,7 @@ public static IFramingElementProperty PileFramingElementProperty(this FamilyInst return framingProperty; // Convert the material to BHoM - BH.oM.Physical.Materials.Material material = familyInstance.FramingMaterial(settings, refObjects); + BH.oM.Physical.Materials.Material material = familyInstance.StructuralMaterial(settings, refObjects); IProfile profile = familyInstance.Symbol.ProfileFromRevit(settings, refObjects); diff --git a/Revit_Core_Engine/Query/LocationSurface.cs b/Revit_Core_Engine/Query/LocationSurface.cs new file mode 100644 index 000000000..255fb5957 --- /dev/null +++ b/Revit_Core_Engine/Query/LocationSurface.cs @@ -0,0 +1,70 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2026, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using Autodesk.Revit.DB; +using BH.Engine.Adapters.Revit; +using BH.oM.Adapters.Revit.Settings; +using BH.oM.Base.Attributes; +using BH.oM.Geometry; +using System; +using System.Collections.Generic; +using System.ComponentModel; + +namespace BH.Revit.Engine.Core +{ + public static partial class Query + { + /***************************************************/ + /**** Public methods ****/ + /***************************************************/ + + [Description("Queries a Revit pad foundation to find its location surface.")] + [Input("padFoundation", "Revit pad foundation to be queried.")] + [Input("settings", "Optional, settings to be used when extracting the location surface.")] + [Output("locationSurface", "BHoM location surface queried from the input pad foundation.")] + public static PlanarSurface LocationSurfacePadFoundation(this FamilyInstance padFoundation, RevitSettings settings) + { + settings = settings.DefaultIfNull(); + + List topFaces = new List(); + foreach (Autodesk.Revit.DB.Face f in padFoundation.Faces(new Options(), settings)) + { + PlanarFace pf = f as PlanarFace; + if (pf == null) + continue; + + if (Math.Abs(1 - pf.FaceNormal.DotProduct(XYZ.BasisZ)) <= BH.oM.Adapters.Revit.Tolerance.Angle) + topFaces.Add(pf); + } + + if (topFaces.Count == 1) + return topFaces[0].FromRevit(); + else + { + BH.Engine.Base.Compute.RecordError($"Failed to extract geometry from pad foundation. ElementId: {padFoundation.Id.Value()}"); + return null; + } + + /***************************************************/ + } + } +} diff --git a/Revit_Core_Engine/Query/MullionElementProperty.cs b/Revit_Core_Engine/Query/MullionElementProperty.cs index 0c05ed383..a9e0cd9ef 100644 --- a/Revit_Core_Engine/Query/MullionElementProperty.cs +++ b/Revit_Core_Engine/Query/MullionElementProperty.cs @@ -54,7 +54,7 @@ public static FrameEdgeProperty MullionElementProperty(this Mullion mullion, Rev return frameEdgeProperty; // Convert the material to BHoM - BH.oM.Physical.Materials.Material material = mullion.FramingMaterial(settings, refObjects); + BH.oM.Physical.Materials.Material material = mullion.StructuralMaterial(settings, refObjects); // Convert the profile to BHoM IProfile profile = mullion.MullionType.ProfileFromRevit(settings, refObjects); diff --git a/Revit_Core_Engine/Query/FramingMaterial.cs b/Revit_Core_Engine/Query/StructuralMaterial.cs similarity index 91% rename from Revit_Core_Engine/Query/FramingMaterial.cs rename to Revit_Core_Engine/Query/StructuralMaterial.cs index 0091c7a0d..96d769496 100644 --- a/Revit_Core_Engine/Query/FramingMaterial.cs +++ b/Revit_Core_Engine/Query/StructuralMaterial.cs @@ -37,12 +37,13 @@ public static partial class Query /**** Public methods ****/ /***************************************************/ + [PreviousVersion("9.1", "BH.Revit.Engine.Core.Query.FramingMaterial(Autodesk.Revit.DB.FamilyInstance, BH.oM.Adapters.Revit.Settings.RevitSettings, System.Collections.Generic.Dictionary>)")] [Description("Extracts a BHoM representation of material from Revit FamilyInstance representing a framing element.")] [Input("familyInstance", "Revit FamilyInstance to be queried.")] [Input("settings", "Revit adapter settings to be used while performing the query.")] [Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] [Output("material", "BHoM representation of material extracted from Revit FamilyInstance representing a framing element.")] - public static BH.oM.Physical.Materials.Material FramingMaterial(this FamilyInstance familyInstance, RevitSettings settings, Dictionary> refObjects = null) + public static BH.oM.Physical.Materials.Material StructuralMaterial(this FamilyInstance familyInstance, RevitSettings settings, Dictionary> refObjects = null) { settings = settings.DefaultIfNull();