Number seperators changed

unhandled

(A Giehr) #1

I feel that the way the number seperators in Rhino 6 are determined has changed.

Is it possible, that Rhino 5 uses the Rhino language to detemine them and Rhino 6 uses the seperator set in the windows options?


(Nathan 'jesterKing' Letwory) #2

In theory Rhino 6 should still use the decimal dot as separator, but there have been cases where this is a bit confused.

Are you able to pinpoint where feel this difference between v5 and v6 are clearest?


(A Giehr) #3

I maybe should have metioned that i mostly work on german, dutch and belgian PCs. We have a simple txt- file to change some values like scale factors and convert them to double in Rhinoscript.

While the german customers use the german language pack of Rhino, the others use the english one. We have a setting, whre the customer has to select the language he uses.

In Rhino 5 we always needed to replace the comma in the string comming from our settings txt with a dot before converting, when the english language pack was used and vice versa.

In Rhino 6 it seems that this has changed. The english language pack seems to expect the comma as seperator when the PC language is german. I did not have the chance to test it on an english PC. Changing the PC language to english did not do the trick, but i´m not sure, if the default seperator is changed, when you change the PC language.


(Nathan 'jesterKing' Letwory) #4

So this is when you use a RhinoScript code to read in the file and do the conversion?

Can you post a minimal example that shows this problem?

I run with my Windows language settings set to Finnish, where also the comma is used as decimal separator. I suppose I could also test with Dutch, as that is my mother tongue.

I’d like to be able to replicate with what you have.


(A Giehr) #5

Sure, i can do that.

First here´s a short example of one of the records in the settings file

[FR-Stich]
lengthFactorNormal=6,667
lengthFactorShort=4,44

And here´s how i convert it. The “s” is a variable that determines whether german or english is selected in another settings file. German would be “0”.

If s = 0 Then
lenghtFactor = CDbl(Replace(Rhino.GetSettings (file, strSection, “lengthFactorNormal”),".",","))
widthFactor = CDBL(Replace(Rhino.GetSettings(file, strSection, “widthFactor”),".",","))
Else
lenghtFactor = CDbl(Replace(Rhino.GetSettings (file, strSection, “lengthFactorNormal”),",","."))
widthFactor = CDBL(Replace(Rhino.GetSettings(file, strSection, “widthFactor”),",","."))
End If

In Rhino 5 it works fine as long as the language pack and the language from our settings match. In Rhino 6 it works on a german pc with german language pack and german selected, but messes up when i use the english language pack and select english in our settings.


(A Giehr) #6

I´m not sure, whether its important, but these values are in mm. They are later used to calculate a scalfefactor. Something like : Scalefactor = (lenghtOfObject + lenghtFactor) / lenghtOfObject


#7

Same with my Swedish keyboard.

Off topic, but do you know of any software that can intercept the comma on the number key part of the keyboard?

In many softwares only the dot is valid as a decimal separator, and then that silly (Swedish) comma is useless and thus just annoying.

// Rolf


#8

You can use “Microsoft Keyboard Layout Creator 1.4” to create a new keyboard layout.
I used this utility to replace the comma on the number pad of my german keyboard.


#9

I tried replacing the comma with dot, but nothing changed. :frowning:


(Nathan 'jesterKing' Letwory) #10

It is a language/culture setting that you can change in Windows (under langage and region settings, additional format settings)


(Nathan 'jesterKing' Letwory) #11

I still haven’t gotten around checking your script, but there were some changes regarding number conversions - those are donein many places now against invariant culture. I have to check your script to see how it affects your case.


#12

That’s also what I would have expected. I’ve tried changing it (see picture) but no go. It’s driving me crazy.

(Sorry for interupting the thread…)

// Rolf


#13

You need to install the modified keyboard layout (after exporting it as an “.exe” IIRC).
Then it should be selectable in Windows language controls.


#14

Ah, there it was! Now it works. I had only run setup and restarted, but not selected the new layout.

Many thanks!

// Rolf


#15

The comma/period confusion on my keyboard drove me nuts until I found this solution.
It would be a nice touch if the seperator could be selected in Rhino preferences imho.
But anyway, at least there is a workaround.

Glad I could help.
Cheers, Norbert


(Nathan 'jesterKing' Letwory) #16

@a.giehr, I have looked now at this for a while, but I can’t see anything that stands out.

@pascal, do you have an idea why CDbl acts like it does? Or do you know who does have a better clue?


(Pascal Golay) #17

I don’t see yet, and I am sure this is all correct in the real code but, just in case — I see typos in the example code above

lengthFactorNormal=6,667
....
....
If s = 0 Then
lenghtFactor = CDbl(Re

-Pascal


(Nathan 'jesterKing' Letwory) #18

Ah yes, I already worked aroun those. Here are the two files I used to test with:

decimalseptest.ini (80 Bytes)
decimalseptest.rvb (930 Bytes)

The RVB:

Option Explicit
Call Main()
Sub Main()
	Dim file, arrSections, strSection, arrEntries, strEntry, strValue
	Dim lengthFactor, widthFactor

	file = Rhino.OpenFileName("Open", "Initialization Files (*.ini)|*.ini||")
	Dim s
	s = 1
	strSection = "FR-Stich"
	Dim strLengthFactor, strWidthFactor
	strLengthFactor = Rhino.GetSettings(file, strSection, "lengthFactorNormal")
	strWidthFactor = Rhino.GetSettings(file, strSection, "widthFactor")
	If s = 0 Then
		lengthFactor = CDbl(Replace(Rhino.GetSettings(file, strSection, "lengthFactorNormal"), ".", ","))
		widthFactor = CDBL(Replace(Rhino.GetSettings(file, strSection, "widthFactor"), ".", ","))
	Else
		lengthFactor = CDbl(Replace(Rhino.GetSettings(file, strSection, "lengthFactorNormal"), ",", "."))
		widthFactor = CDBL(Replace(Rhino.GetSettings(file, strSection, "widthFactor"), ",", "."))
	End If
	Rhino.Print(lengthFactor)
	Rhino.Print(widthFactor)
End Sub

The INI

[FR-Stich]
lengthFactorNormal=6,667
widthFactor=3,43
lengthFactorShort=4,44


(Pascal Golay) #19

Hi Nathan - it seems more predictable if the string from the ini file is read in and set to a variable, then sent to Replace() etc rather than reading it on the fly inside Replace().

-Pascal


(A Giehr) #20

So i tried refactoring my code like this :

strLengthFactor = Rhino.GetSettings(file, strSection, “lengthFactorNormal”)
strWidthFactor = Rhino.GetSettings(file, strSection, “widthFactor”)

If s = 0 Then
strLengthFactor = Replace(strLengthFactor,".",",")
strWidthFactor = Replace(strWidthFactor,".",",")
Else
strLengthFactor = Replace(strLengthFactor,",",".")
strWidthFactor = Replace(strWidthFactor,",",".")
End If

lengthFactor = CDbl(strLengthFactor)
widthFactor = CDbl(strWidthFactor)

The behavior is still the same, but at least a lot faster.

Rhino 6 :
German language pack with s = 0 : Perfect result.
English language pack with s=1 : Messed up.

Both working fine in Rhino 5