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

    Setting a certain unit as standard

    Scheduled Pinned Locked Moved Developers' Forum
    13 Posts 3 Posters 524 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.
    • M Offline
      meeta
      last edited by

      so says we ask the user to input this

      'number'

      this is in inches automatically?

      and say i ask the user to input

      'number' and then put 'number'.to_mm

      does that mean it is converting inches in to mm?

      Meet A

      1 Reply Last reply Reply Quote 0
      • M Offline
        MartinRinehart
        last edited by

        This won't set units, but will tell you what is set:

        
        def units
        	x = '120'.to_l.inspect.to_i
        	if x == 120 
        		return 'in'
        	elsif x == 1440 
        		return 'ft'
        	elsif x == 4 
        		return 'mm'
        	elsif x == 47 
        		return 'cm'
        	elsif x == 4724 
        		return 'm'
        	else 
        		throw "Unknown units"
        	end
        end
        
        

        I wouldn't trust this code until a bunch more people test it.

        Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          If you take an input number, a pure integer - then SU will assume it's in inches.
          If the input that's an string that has a unit notation, like "20mm" or "30'" -then you can use String.to_l (http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/string.html#to_l) to convert it into a Length. (Length is the internal unit of SU - in inches.)

          If you take a Length unit and use the .to_s method - then it will print out the value in the unit of the current Model.

          If you have some fixed formulas you type in the code you find easier to type in mm then use the methods of the Numeric class.
          100.mm + 320.mm

          So in overview:
          Ensure input is converted into SU's internal unit (inches). Make use of the Length class.
          When you need to output the values to the user you use the .to_s method of the Length class which makes SU do all the dirty work of formatting the value to fit the current model's settings.

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • M Offline
            MartinRinehart
            last edited by

            @meeta said:

            so says we ask the user to input this 'number' this is in inches automatically?

            No. Number is in user's units. If it's a length, SketchUp stores it internally in inches, displays it in user's units.

            And I apologize on behalf of myself and the rest of the citizens of my country for causing this confusion. Maybe some day we'll join the rest of the world. Maybe.

            Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @martinrinehart said:

              This won't set units, but will tell you what is set:

              
              > def units
              > 	x = '120'.to_l.inspect.to_i
              > 	if x == 120 
              > 		return 'in'
              > 	elsif x == 1440 
              > 		return 'ft'
              > 	elsif x == 4 
              > 		return 'mm'
              > 	elsif x == 47 
              > 		return 'cm'
              > 	elsif x == 4724 
              > 		return 'm'
              > 	else 
              > 		throw "Unknown units"
              > 	end
              > end
              > 
              

              I wouldn't trust this code until a bunch more people test it.

              '120'.to_l This will convert the String into a Length unit, assuming the value is in the current model Unit. So if your model unit is mm - then it will produce 4.7244094488189 inches.

              120.to_l This will convert the Integer into a Length unit - assuming the value is inches.

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • M Offline
                meeta
                last edited by

                Best option for me, I reckon ask the user to input in his or her own units and then convert to mm for my calculations..
                no offense to anyone.. but s ketchup should've been based on the metric system..

                Meet A

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  @meeta said:

                  no offense to anyone.. but s ketchup should've been based on the metric system..

                  Agree with you there. Then again - I'm a metric user. πŸ˜‰

                  @meeta said:

                  Best option for me, I reckon ask the user to input in his or her own units and then convert to mm for my calculations..

                  Why do you have to do this? With the helper methods of the Numeric class that let you write stuff like 100.mm in your code? surely it's better to let the code do the work instead of the user?

                  Thomas Thomassen β€” SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • M Offline
                    meeta
                    last edited by

                    Because my constants are based on eurocode 3.. Which I definitely cannot change. I have constant such as this 25 kN/mm.. which I cannot avoid..

                    I reckon.. I will put something like this every time I multiply

                    h.to_mm*250

                    Meet A

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      Yes, that's how you need to treat units in SU.

                      Thomas Thomassen β€” SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • M Offline
                        meeta
                        last edited by

                        Thank you Thom and Martin.. I understand better now : πŸ˜„

                        Meet A

                        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