Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions BHoMUpgrades/CustomUpgrades/v93.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

using BH.oM.Versioning;
using System;
using System.Collections.Generic;

namespace BH.Upgraders
Expand Down Expand Up @@ -114,6 +115,62 @@ public static Dictionary<string, object> UpgradeAreaTagSettings(Dictionary<strin
return newVersion;
}

/***************************************************/

[VersioningTarget("BH.Revit.oM.ElementRelationships.PlacementSettings")]
public static Dictionary<string, object> UpgradePlacementSettings(Dictionary<string, object> oldVersion)
{
if (oldVersion == null)
return null;

Dictionary<string, object> newVersion = new Dictionary<string, object>(oldVersion);

if (newVersion.ContainsKey("PlacementCollections"))
{
newVersion.Remove("ElementPlacementSettings");
return newVersion;
}

if (!newVersion.TryGetValue("ElementPlacementSettings", out object oldPlacementsObject))
return newVersion;

List<object> placements = new List<object>();
IEnumerable<object> oldPlacements = oldPlacementsObject as IEnumerable<object>;
if (oldPlacements != null)
{
foreach (object item in oldPlacements)
{
if (item is Dictionary<string, object> 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<string, object> defaultCollection = new Dictionary<string, object>
{
{ "_t", "BH.Revit.oM.ElementRelationships.PlacementCollection" },
{ "BHoM_Guid", Guid.NewGuid() },
{ "Name", "Default Collection" },
{ "Placements", placements }
};

newVersion["PlacementCollections"] = new List<object> { defaultCollection };
newVersion.Remove("ElementPlacementSettings");

return newVersion;
}

/***************************************************/
/**** Private Methods ****/
/***************************************************/
Expand Down
Loading