diff --git a/BHoMUpgrader60/Converter.cs b/BHoMUpgrader60/Converter.cs index 58bb6fc..80d759e 100644 --- a/BHoMUpgrader60/Converter.cs +++ b/BHoMUpgrader60/Converter.cs @@ -38,12 +38,63 @@ 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 IEnumerable)?.ToList(); + + List ratios = null; + object ratiosObj; + + if (matComp.TryGetValue("Ratios", out ratiosObj)) + { + List list = (ratiosObj as IEnumerable)?.ToList(); + if (list != null) + ratios = list.Cast().ToList(); + } + + if (ratios != null) + { + foreach (double ratio in ratios) + { + volumes.Add(totalVolume * ratio); + } + } + } + } + + newVersion["Materials"] = materials; + newVersion["Volumes"] = volumes; + return newVersion; + + } + /***************************************************/ } }