How to manage decimal separator in an existing plugin

Hello, I’m adapting Jim Hamilton’s rack_and_pinion plugin to my needs.
(I’m not very good at understanding Ruby for SketchUp, but I try and sometimes succeed.)

The plugin doesn’t work if the decimal separator of the computer is “,” (in France for example).

The “.to_l” is the problem. I tried different things without success. Could you help me ?

The code is here : https://drive.google.com/file/d/1h18T_LGxffUVJmJgs_eTxr48JY7p4xjv/view
(The list of the codes is here : https://sites.google.com/site/spirixcode/code )

Best regards,
R.

Maybe ping @jimhami42 ?

The comma vs dot appears only when a length is formatted as a string, it has no meaning or existence in the length itself. I don’t know exactly what you are trying to do and don’t have time to dig through Jim’s code, but converting back and forth between strings and lengths is what you need to work on.

The code comments say, “cannot use “,” as a decimal separator”.

Just a shot in the dark, at line 117:

if input
    # Normalize decimal separator to period
    input.map! { |i| i.is_a?(String) ? i.gsub(',', '.') : i }
1 Like

I’m not sure what the problem might be, but at the very end of the code is this bit that initializes the defaults. Try changing the decimals to commas in this part and see if that helps.

>       def jimhami42_rack_and_pinion_init_dictionary(dict)
>         dict['teeth'] = '12'
>         dict['p_ang'] = '20.0'
>         dict['p_rad'] = '1"'
>         dict['s_ang'] = '2.0'
>         dict['h_dia'] = '0"'
>         dict['k_width'] = '0"'
>         dict['type'] = 'Pinion'
>         dict['thick'] = '0"'
>         dict['axis'] = 'No'
>         dict['plus'] = '0.0'
>         dict['minus'] = '0.0'
>       end
1 Like

Thanks @jimhami42 , I added that :

if Sketchup::RegionalSettings.decimal_separator == '.'
	dict['teeth'] = '17'
	dict['p_ang'] = '20.0'
	dict['module'] = '2.0'
	dict['s_ang'] = '3.0'
	dict['h_dia'] = '0'
	dict['k_width'] = '0'
	dict['type'] = 'Pignon'
	dict['thick'] = '10'
	dict['plus'] = '0.0'
	dict['minus'] = '0.0'
else
	dict['teeth'] = '17'
	dict['p_ang'] = '20,0'
	dict['module'] = '2,0'
	dict['s_ang'] = '3,0'
	dict['h_dia'] = '0'
	dict['k_width'] = '0'
	dict['type'] = 'Pignon'
	dict['thick'] = '10'
	dict['plus'] = '0,0'
	dict['minus'] = '0,0'
end

and it seems working :+1:.

(My modifications are about the french metric and module system.)

I can also test the user entries, maybe with @3DxJFD suggestion, but it’s not “urgent” :slight_smile:

Thanks :pray: to all the answers.

3 Likes