From 43263d97899d61e44bdd665c59927e62d3ac9f9d Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Fri, 30 Sep 2022 11:49:50 +0200 Subject: [PATCH 1/3] Add custom upgrader for RevitMaterialTakeoff --- BHoMUpgrader60/Converter.cs | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/BHoMUpgrader60/Converter.cs b/BHoMUpgrader60/Converter.cs index 58bb6fc..d821fd2 100644 --- a/BHoMUpgrader60/Converter.cs +++ b/BHoMUpgrader60/Converter.cs @@ -38,12 +38,70 @@ public class Converter : Base.Converter public Converter() : base() { PreviousVersion = "5.3"; + + ToNewObject.Add("BH.oM.Adapters.Revit.RevitMaterialTakeOff", UpgradeRevitMaterialTakeoff); } /***************************************************/ /**** Private Methods ****/ /***************************************************/ + public static Dictionary UpgradeRevitMaterialTakeoff(Dictionary oldVersion) + { + Dictionary newVersion = new Dictionary(); + newVersion["_t"] = "BH.oM.Physical.Materials.VolumetricMaterialTakeoff"; + + double totalVolume = 0; + object volumeObj; + if (oldVersion.TryGetValue("TotalVolume", out volumeObj) && volumeObj is double) + totalVolume = (double)volumeObj; + + List materials = new List(); + List volumes = new List(); + object matCompObj; + if (oldVersion.TryGetValue("MaterialComposition", out matCompObj)) + { + Dictionary matComp = matCompObj as Dictionary; + if (matComp != null) + { + + object materialsObj; + if(matComp.TryGetValue("Materials", out materialsObj)) + materials = materialsObj as List; + + List ratios = null; + object ratiosObj; + + if (matComp.TryGetValue("Ratios", out ratiosObj)) + { + ratios = ratiosObj as List; + if (ratios == null) + { + List list = ratiosObj as List; + if (list != null) + ratios = list.Cast().ToList(); + } + } + + if (ratios != null) + { + foreach (double ratio in ratios) + { + volumes.Add(totalVolume * ratio); + } + } + } + } + //"BHoM_Guid", "CustomData", "Name", "Tags", "Fragments" + newVersion["Materials"] = materials; + newVersion["Volumes"] = volumes; + return newVersion; + //newVersion["Name"] = ""; + //newVersion["BHoM_Guid"] = Guid.NewGuid(); + //newVersion["CustomData"] = new Dictionary(); + + } + /***************************************************/ } } From bbad3c2da8f0aa56275cf2748e12790a1fcb4b41 Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Fri, 30 Sep 2022 11:54:42 +0200 Subject: [PATCH 2/3] Remove commented out code --- BHoMUpgrader60/Converter.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/BHoMUpgrader60/Converter.cs b/BHoMUpgrader60/Converter.cs index d821fd2..6fd9fc5 100644 --- a/BHoMUpgrader60/Converter.cs +++ b/BHoMUpgrader60/Converter.cs @@ -92,13 +92,10 @@ public static Dictionary UpgradeRevitMaterialTakeoff(Dictionary< } } } - //"BHoM_Guid", "CustomData", "Name", "Tags", "Fragments" + newVersion["Materials"] = materials; newVersion["Volumes"] = volumes; return newVersion; - //newVersion["Name"] = ""; - //newVersion["BHoM_Guid"] = Guid.NewGuid(); - //newVersion["CustomData"] = new Dictionary(); } From d4f243df877032fe5ecde2a21c56a64498f8309f Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Thu, 13 Oct 2022 14:43:41 +0200 Subject: [PATCH 3/3] Fix RevitMaterialTakeoff versioning --- BHoMUpgrader60/Converter.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/BHoMUpgrader60/Converter.cs b/BHoMUpgrader60/Converter.cs index 6fd9fc5..80d759e 100644 --- a/BHoMUpgrader60/Converter.cs +++ b/BHoMUpgrader60/Converter.cs @@ -67,20 +67,16 @@ public static Dictionary UpgradeRevitMaterialTakeoff(Dictionary< object materialsObj; if(matComp.TryGetValue("Materials", out materialsObj)) - materials = materialsObj as List; + materials = (materialsObj as IEnumerable)?.ToList(); List ratios = null; object ratiosObj; if (matComp.TryGetValue("Ratios", out ratiosObj)) { - ratios = ratiosObj as List; - if (ratios == null) - { - List list = ratiosObj as List; - if (list != null) - ratios = list.Cast().ToList(); - } + List list = (ratiosObj as IEnumerable)?.ToList(); + if (list != null) + ratios = list.Cast().ToList(); } if (ratios != null)