Web dialog fractions conversion
-
My model is set to millimeters 0.001 precision.
Using a web dialog I enter the following values and use text.to_l to convert
These are as expected
- 400 ends up as 400.000mm
- 300mm ends up as 300.000mm
- 16" ends up as 406.400mm
- 3 7/8 ends up as 3.875mm This one is suspicious
But then this happens
- 2 1/2" ends up as 2.500mm
Is this a bug or am I doing something wrong?
I suppose that I could check for '/' and then treat and if found multiply the result by
25.4 if metric. It appears that I will have to do some testing to see if there are any other conversion issues. -
After further testing it appears that this is the only conversion that fails ( I'm currently only interested in mm and inches )
I have tested Version 7,8 and 2013 and all give the same results.
I have also tested Sketchup's input box and it also gives the same results.def get_value( text )
tmp = text.to_lif ( @@metric == true && text.index( '/' ) != nil )
val = ( ( tmp * 25.4 ).to_s + '"' ).to_l
else
val = tmp
endputs val
return val
end -
Have you read Thomas' "Dealing with Units in SketchUp" ?
http://www.thomthom.net/thoughts/2012/08/dealing-with-units-in-sketchup/Always assume the user wishes to enter values in model units.
-
@garry k said:
But then this happens
- 2 1/2" ends up as 2.500mm
Is this a bug or am I doing something wrong?
It works for me if I make sure to escape the inch symbol, or use a single quoted string:
` n = '2 1/2"'.to_l
0.0984251968503937n = "2 1/2"".to_l
0.0984251968503937`You can test if a string contains a double quoted character thus:
if num =~ /\"/
-
I'm on a different wave length here.
If you have a Sketchup inputbox that has a length.
The model is in millimeters and use precision of 0.001 just because.Now the user enters 2 1/2" into the input box ( they will never understand that you need to escape the double quote.
It comes out as 2.500mm
This is NOT as expected - regardless.
I know myself that I work mostly in millimeters but feel quite at home going back and forth. All the other built in conversions work just fine. Just not this one.
Furthermore - my experience in CAD goes back to DOS. I allow my users ( when I code in C++ ) to enter inches when in millimeters and visa versa. Additionally I allow users to enter mathematical expressions that I evaluate such as:
in milimetes
(905 - 20) / 5
which evaluates as 177mmIf 95% of logical data entry works - and 5% doesn't - users will naturally tend to see that as a bug.
But not to worry as I have a work around - but not for Sketchup inputbox as we don't get to see what the user entered.
-
http://sketchucation.com/forums/viewtopic.php?t=36722
There are some conversion methods in there to take inspiration from..
-
Thanks Jolran - this is helpful. I can perhaps add math expression parsing at a later date!
-
@garry k said:
This is NOT as expected - regardless.
I know myself that I work mostly in millimeters but feel quite at home going back and forth. All the other built in conversions work just fine. Just not this one.
Yes I think it IS a bug.
Today I tested with a model set to decimal feet (0.001) and got this:
` '2 1/2"'.to_l
30.0Sketchup::format_length('2 1/2"'.to_l)
2.500'`So the inch symbol is ignored.
But in a model set to inches:
"2.54'".to_l %(#008000)[30.48]
So it seems the foot symbol works, IF the numeric is decimal.But IF it is fractional (model set to inches):
"2 1/2'".to_l %(#008000)[24.0]
**So I agree. It is a bug issue with fractional expressions.
ADD: The error also occurs within the VCB (Measurements Box) !**
Advertisement