• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Setting a certain unit as standard

Scheduled Pinned Locked Moved Developers' Forum
13 Posts 3 Posters 524 Views
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 18 Nov 2009, 19:03

    I created a small plugin that calculates the reinforcement for concrete beams and columns. I gave it to my friends to show off, but unfortunately, he was using inches and I was using mm and it was quiet the embarrassing moment 😳. Is there a way to set the unit as mm in the start of the program. Is this permitted by sketchup? or is there is way to not convert the units every time?

    Meet A

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 18 Nov 2009, 19:40

      SU always uses inches internally. The Numeric and Length class has methods to deal with this. You must always work around inches.

      Error 404 (Not Found)!!1

      favicon

      (code.google.com)

      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 18 Nov 2009, 20:31

        @meeta said:

        Is there a way to set the unit as mm in the start of the program.

        That's a darn good question. Anyone?

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

        1 Reply Last reply Reply Quote 0
        • M Offline
          meeta
          last edited by 18 Nov 2009, 20:42

          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 18 Nov 2009, 20:55

            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
            • T Offline
              thomthom
              last edited by 18 Nov 2009, 21:03

              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 18 Nov 2009, 21:06

                @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
                • T Offline
                  thomthom
                  last edited by 18 Nov 2009, 21:08

                  @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 18 Nov 2009, 21:34

                    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
                    • T Offline
                      thomthom
                      last edited by 18 Nov 2009, 21:41

                      @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 18 Nov 2009, 21:50

                        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
                        • T Offline
                          thomthom
                          last edited by 18 Nov 2009, 22:05

                          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 18 Nov 2009, 22:53

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

                            Meet A

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

                            Advertisement