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
51 changes: 51 additions & 0 deletions BHoMUpgrader60/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object> UpgradeRevitMaterialTakeoff(Dictionary<string, object> oldVersion)
{
Dictionary<string, object> newVersion = new Dictionary<string, object>();
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<object> materials = new List<object>();
List<double> volumes = new List<double>();
object matCompObj;
if (oldVersion.TryGetValue("MaterialComposition", out matCompObj))
{
Dictionary<string, object> matComp = matCompObj as Dictionary<string, object>;
if (matComp != null)
{

object materialsObj;
if(matComp.TryGetValue("Materials", out materialsObj))
materials = (materialsObj as IEnumerable<object>)?.ToList();

List<double> ratios = null;
object ratiosObj;

if (matComp.TryGetValue("Ratios", out ratiosObj))
{
List<object> list = (ratiosObj as IEnumerable<object>)?.ToList();
if (list != null)
ratios = list.Cast<double>().ToList();
}

if (ratios != null)
{
foreach (double ratio in ratios)
{
volumes.Add(totalVolume * ratio);
}
}
}
}

newVersion["Materials"] = materials;
newVersion["Volumes"] = volumes;
return newVersion;

}

/***************************************************/
}
}