sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Web dialog fractions conversion

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 3 Posters 357 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G Offline
      Garry K
      last edited by

      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

      1. 400 ends up as 400.000mm
      2. 300mm ends up as 300.000mm
      3. 16" ends up as 406.400mm
      4. 3 7/8 ends up as 3.875mm This one is suspicious

      But then this happens

      1. 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.

      1 Reply Last reply Reply Quote 0
      • G Offline
        Garry K
        last edited by

        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_l

        if ( @@metric == true && text.index( '/' ) != nil )
        val = ( ( tmp * 25.4 ).to_s + '"' ).to_l
        else
        val = tmp
        end

        puts val

        return val
        end

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          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.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            @garry k said:

            But then this happens

            1. 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.0984251968503937

            n = "2 1/2"".to_l
            0.0984251968503937`

            You can test if a string contains a double quoted character thus:
            if num =~ /\"/

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • G Offline
              Garry K
              last edited by

              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 177mm

              If 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.

              1 Reply Last reply Reply Quote 0
              • jolranJ Offline
                jolran
                last edited by

                http://sketchucation.com/forums/viewtopic.php?t=36722

                There are some conversion methods in there to take inspiration from..

                1 Reply Last reply Reply Quote 0
                • G Offline
                  Garry K
                  last edited by

                  Thanks Jolran - this is helpful. I can perhaps add math expression parsing at a later date!

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @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.0

                    Sketchup::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) !**

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement