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

    Return values

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 3 Posters 871 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      100.mm becomes a Length class (which is inches.)

      You must convert back mm, using .to_mm, but because you cubed it, you have to "cube" the conversion

      "%fmm#{179.chr}" % (@width * @breadth * @height).to_mm.to_mm.to_mm
      

      see Kernel.sprintf() for info on format strings

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • P Offline
        PaulG
        last edited by

        Thanks Dan, although .to_mm.to_mm.to_mm looks like some kind of comedy code. I gotta say Ruby seems the most obscure, non-sensical language I have used so far.

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

          @dan rathbun said:

          You must convert back mm, using .to_mm, but because you cubed it, you have to "cube" the conversion

          It's better to use .to_l - then when that Length instance is outputted as string it's printed in the user's units.
          As for area - use Sketchup.format_area

          Unfortunately there is no method for volume - they left that one out. So in that particular instance you need to write the conversion from cubed inches to user units yourself.

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

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

            prompts = ["Width mm", "Breadth mm", "Height mm"] defaults = ["100", "100", "100"]

            Let SketchUp handle the units for you. If you feed the input box Length objects as defaults - it converts the user input to Length's for you.
            defaults = [100.mm, 100.mm, 100.mm]

            It's better to work with units in SketchUp's units - internally inches - and always ensure you have Length objects when you output to the user. That way the user gets the units in his/her preferred unit and you don't have to do a thing.

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

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

              There was another topic on this issue, I think I may have posted a method in there.
              Or.. hmmm... It may have a "[Code]" prefix in the title.
              ADD: found it: Volume of Multiple Groups
              You might get some ideas from that, and there is a link to one of TIG's old utilities.


              Anyway.. TT... One thing you or TIG have not done yet is a "Units: The Lost Manual" 😆

              I'm not here much anymore.

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

                @dan rathbun said:

                Anyway.. TT... One thing you or TIG have not done yet is a "Units: The Lost Manual" 😆

                That is in fact on my list to write up.

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

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

                  @paulg said:

                  Thanks Dan, although .to_mm.to_mm.to_mm looks like some kind of comedy code. I gotta say Ruby seems the most obscure, non-sensical language I have used so far.

                  Of course it does. It's not Ruby's fault, that is not Ruby best practice.

                  There are many "missing" methods in various API classes.

                  In fact what we are missing here, are Area and Volume classes. When you multiply 2 Length instance objects, they get converted to Float.. and then you cannot tell what the math ops were to end up with the value.

                  In other words... math on a Length object, by any other Numeric subclass, should return a new Length object. (Like adding the frontage of building lots along a right-of-way, or math ops with wall lengths to arrive at a perimeter length.)

                  Multiplying two Length objects, should return a new Area object.

                  Multiplying 3 Length objects, OR an Area object by a Length object, should return a new Volume object.

                  However, multiplying Area objects, by other non-length Numeric objects, should result in a new larger Area object.

                  .. etc.

                  Problem is, current version of SketchUp would not know how to handle these new classes.

                  I'm not here much anymore.

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

                    @dan rathbun said:

                    Anyway.. TT... One thing you or TIG have not done yet is a "Units: The Lost Manual" 😆

                    Link Preview Image
                    Dealing with Units in SketchUp

                    There are extensions to the base classes in SketchUp’s Ruby API which often new SketchUp plugin developers overlook. If you aren’t aware of them you might find yourself reinventing many…

                    favicon

                    Procrastinators Revolt! (www.thomthom.net)

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

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

                      👍 👍

                      NO faults that I can see, after a quick read.

                      I'm not here much anymore.

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

                        @dan rathbun said:

                        :thumb: 👍

                        NO faults that I can see, after a quick read.

                        I'm sure there's some input to be made on the library I posted at GitHub - linked at the bottom. I'd collected it from various helper methods from different plugins of mine. The volume and area functions was originally not in separate classes - but I liked idea idea of Area and Volume as separate classes.

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

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

                          @thomthom said:

                          @dan rathbun said:

                          ... but I liked idea idea of Area and Volume as separate classes.

                          I also ! (as I said above.)

                          And the API needs these, and the app needs to use them.

                          I'm not here much anymore.

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

                            And locale handling for Floats.

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

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

                              @dan rathbun said:

                              And the API needs these, and the app needs to use them.

                              Yes - agree. Your idea about multiply two Length to get and Area, and Area with Length to get a Volume is very elegant. I'd very much like to see this into SU9.

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

                              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