Skip to content

Commit

Permalink
Fix(Revit) : correctly parse units coming from other applications (#3054
Browse files Browse the repository at this point in the history
)

* correctly parse units coming from other applications

* test for formatted string

---------

Co-authored-by: Connor Ivy <[email protected]>
  • Loading branch information
connorivy and Connor Ivy authored Nov 21, 2023
1 parent 509239c commit 068c786
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public void SetInstanceParameters(Element revitElement, Base speckleElement, Lis

var rp = revitParameterById.ContainsKey(spk.Key) ? revitParameterById[spk.Key] : revitParameterByName[spk.Key];

TrySetParam(rp, sp.value, applicationUnit: sp.applicationUnit);
TrySetParam(rp, sp.value, sp.units, sp.applicationUnit);
}
}

Expand Down Expand Up @@ -500,9 +500,9 @@ private void TrySetParam(DB.Parameter rp, object value, string units = "", strin
var val = RevitVersionHelper.ConvertToInternalUnits(Convert.ToDouble(value), rp);
rp.Set(val);
}
else if (Speckle.Core.Kits.Units.IsUnitSupported(units))
else if (TryGetUnitsFromString(units, out string formattedUnits))
{
var val = ScaleToNative(Convert.ToDouble(value), units);
double val = ScaleToNative(Convert.ToDouble(value), formattedUnits);
rp.Set(val);
}
else
Expand Down Expand Up @@ -615,7 +615,7 @@ private Phase GetRevitPhase(DB.Document document, string phaseName)
return null;
}

#endregion
#endregion

#region conversion "edit existing if possible" utilities

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Autodesk.Revit.DB;
using ConverterRevitShared.Extensions;
using RevitSharedResources.Interfaces;
using Speckle.Core.Logging;

namespace Objects.Converter.Revit
{
Expand Down Expand Up @@ -239,5 +240,19 @@ public static ForgeTypeId UnitsToNative(string units)
}
}
#endif

public static bool TryGetUnitsFromString(string units, out string? result)
{
try
{
result = Speckle.Core.Kits.Units.GetUnitsFromString(units);
return !string.IsNullOrEmpty(result);
}
catch (SpeckleException)
{
result = null;
return false;
}
}
}
}

0 comments on commit 068c786

Please sign in to comment.