diff --git a/BHoMUpgrades/CustomUpgrades/v93.cs b/BHoMUpgrades/CustomUpgrades/v93.cs index 41af7c4..9d339fe 100644 --- a/BHoMUpgrades/CustomUpgrades/v93.cs +++ b/BHoMUpgrades/CustomUpgrades/v93.cs @@ -21,6 +21,7 @@ */ using BH.oM.Versioning; +using System; using System.Collections.Generic; namespace BH.Upgraders @@ -114,6 +115,62 @@ public static Dictionary UpgradeAreaTagSettings(Dictionary UpgradePlacementSettings(Dictionary oldVersion) + { + if (oldVersion == null) + return null; + + Dictionary newVersion = new Dictionary(oldVersion); + + if (newVersion.ContainsKey("PlacementCollections")) + { + newVersion.Remove("ElementPlacementSettings"); + return newVersion; + } + + if (!newVersion.TryGetValue("ElementPlacementSettings", out object oldPlacementsObject)) + return newVersion; + + List placements = new List(); + IEnumerable oldPlacements = oldPlacementsObject as IEnumerable; + if (oldPlacements != null) + { + foreach (object item in oldPlacements) + { + if (item is Dictionary placementDict) + { + if (placementDict.TryGetValue("_t", out object type) && + type?.ToString() == "BH.Revit.oM.ElementRelationships.ElementPlacementSettings") + { + placementDict["_t"] = "BH.Revit.oM.ElementRelationships.ElementPlacement"; + } + + placements.Add(placementDict); + } + else + { + placements.Add(item); + } + } + } + + Dictionary defaultCollection = new Dictionary + { + { "_t", "BH.Revit.oM.ElementRelationships.PlacementCollection" }, + { "BHoM_Guid", Guid.NewGuid() }, + { "Name", "Default Collection" }, + { "Placements", placements } + }; + + newVersion["PlacementCollections"] = new List { defaultCollection }; + newVersion.Remove("ElementPlacementSettings"); + + return newVersion; + } + /***************************************************/ /**** Private Methods ****/ /***************************************************/