From 068c78621dd6a03c5108b56b7d274f8f5633cc28 Mon Sep 17 00:00:00 2001 From: connorivy <43247197+connorivy@users.noreply.github.com> Date: Tue, 21 Nov 2023 03:30:05 -0600 Subject: [PATCH] Fix(Revit) : correctly parse units coming from other applications (#3054) * correctly parse units coming from other applications * test for formatted string --------- Co-authored-by: Connor Ivy --- .../ConverterRevitShared/ConversionUtils.cs | 8 ++++---- .../ConverterRevitShared/Partial Classes/Units.cs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/ConversionUtils.cs b/Objects/Converters/ConverterRevit/ConverterRevitShared/ConversionUtils.cs index 7e4ee707d1..4b4dd2cbca 100644 --- a/Objects/Converters/ConverterRevit/ConverterRevitShared/ConversionUtils.cs +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/ConversionUtils.cs @@ -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); } } @@ -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 @@ -615,7 +615,7 @@ private Phase GetRevitPhase(DB.Document document, string phaseName) return null; } - #endregion +#endregion #region conversion "edit existing if possible" utilities diff --git a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/Units.cs b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/Units.cs index 04853c2c3e..6bf3fed706 100644 --- a/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/Units.cs +++ b/Objects/Converters/ConverterRevit/ConverterRevitShared/Partial Classes/Units.cs @@ -1,6 +1,7 @@ using Autodesk.Revit.DB; using ConverterRevitShared.Extensions; using RevitSharedResources.Interfaces; +using Speckle.Core.Logging; namespace Objects.Converter.Revit { @@ -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; + } + } } }