sketchucation logo sketchucation
    • Login
    ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

    Get Current Units

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 4 Posters 1.2k 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.
    • T Offline
      TheDro
      last edited by

      I was wondering if there was a way to get (in a ruby script) the current units that are being used in the model. The reason is that I want to make a dialog box that asks for dimensions from the user and it would be nice if the user could simply enter a numerical value corresponding to the length in the model's current units set in Model Info>Units.

      Someone please let me know if it is possible to do this or if it is somehow unnecessary.

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

        Yes model.options

        See:
        http://code.google.com/apis/sketchup/docs/ourdoc/optionsprovider.html

        Note the code examples, and ThomThoms comments posted at the bottom of the page.

        You will also need to be aware of the conversion methods that the API adds to the Numeric classes (because internally all distances are in inches.)

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          Sketchup.active_model.options["UnitsOptions"]["LengthUnit"]
          returns an integer - this corresponds to the units as follows:

          0 = "
          1 = '
          2 = mm
          3 = cm
          4 = m The whole set of UnitOptions are:
          [["LengthPrecision", 0], ["LengthFormat", 0], ["LengthUnit", 2], ["LengthSnapEnabled", true], ["LengthSnapLength", 0.0393700787401575], ["AnglePrecision", 1], ["AngleSnapEnabled", true], ["SnapAngle", 15.0], ["SuppressUnitsDisplay", true], ["ForceInchDisplay", false]]
          This .to_a is for a SKP with Model Info > Units set to display to nearest-unit, in decimal format, with no unit suffix, in 'mm' units, and snapping to nearest 1 unit, etc...
          Always get values from an options type by 'name' like ["UnitsOptions"]["LengthUnit"], rather than the element 'index' like ["UnitsOptions"][2] because the order they are listed in can change between SUp versions etc...

          TIG

          1 Reply Last reply Reply Quote 0
          • T Offline
            TheDro
            last edited by

            Thanks guys. I love how active this whole forum is.

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

              If you convert a string number into a Length ( .to_l ) and the string contains no unit indication it assumes the units is the current model unit.

              "50".to_l
              Returns a Length: 1.96850393700787 (assuming the model units where mm)

              "50m".to_l
              Returns a Length: 1968.50393700787 regardless of what the model units are because the unit is specified.

              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