Units go wrong on one computer not the other

Units go wrong on one computer not the other

fv2
Enthusiast Enthusiast
412 Views
5 Replies
Message 1 of 6

Units go wrong on one computer not the other

fv2
Enthusiast
Enthusiast

Hey,

 

 maybe this isn’t a Revit API issue but maybe anyone else had this problem… we have a list of strings that we convert to a double. For example.

 

Convert.ToDouble("7.5")

 

then with

 

UnitUtils.ConvertToInternalUnits(7.5, UnitTypeId.Meters)

 

for most computers this works fine, but we have 1 computer where it doesn’t… it makes it 100x bigger the value in feet???

 

we checked in windows the region / decimal settings all the same… signed in as a different user but no luck… reinstalled revit 2022.

 

 Anyone who might have a solution?!

 

 Kind regards,

 Fabian

0 Likes
Accepted solutions (2)
413 Views
5 Replies
Replies (5)
Message 2 of 6

jeremy_tammik
Alumni
Alumni
Accepted solution

If you are using Convert and your OS has anything to do with German-speaking regions or other interesting Culture settings, then that might be the culprit:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 6

fv2
Enthusiast
Enthusiast
Accepted solution

You are right, dont have any German, but on one machine it says the Culture is "en-GB" and the other machine is "nl-NL", so we now added code to make sure its all the same.

 

In case anyone else has this problem here is the code we use:

 

System.Windows.Forms.Application.CurrentCulture = new System.Globalization.CultureInfo("nl-NL");

 

Kind regards,

Fabian

0 Likes
Message 4 of 6

Revitalizer
Advisor
Advisor

Hi,

 

do not change the application's culture since it affects all other add-ins.

 

(System.Windows.Forms.Application.CurrentCulture is equivalent to

System.Threading.Thread.CurrentThread.CurrentCulture; both refer to the same object.)

 

Similarly, setting the CurrentUICulture will interfere with other add-ins too, that can change the UI language of Dynamo, for example.

 

 

Revitalizer

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 5 of 6

fv2
Enthusiast
Enthusiast

Thank you for your response but what can we do to fix this problem? Since its working on one computer but not the other.

 

We found the cause of this problem, but what would be the best solution?

 

kind regards,

Fabian

0 Likes
Message 6 of 6

RPTHOMAS108
Mentor
Mentor

Use InvariantCulture don't try and change culture of user.

 

Your main issue is that your stored values are not in InvariantCulture to begin with. We should always store values in this form (which is basically en-US I believe) if they are being used as inputs accross cultures.

 

So now you would have to know what culture the strings came from to convert to Invariant. We can probably establish the decimal separator of the string (which is all that matters to a double) by looking at what non-number character appears last in a string. e.g. 999.999,99 or 999,999.99

 

So when you know decimal character you can convert 999.999,99 to 999999.99 by two text replace operations (in right order). Or you can use code similar to in link by specifying what the established decimal character of the input string is.

0 Likes