Unit of measurement Ruby API

Hello everyone,
a little help, through Ruby API,
you can determine at the start which unit of measurement is set by the SketchUp program,
whether the inch, feet, meters, centimeters or millimeters are preset…
Thank you
Joseph.

The required keys and values are in

Sketchup.active_model.options['UnitsOptions']

Unfortunately (so far as I know) the meaning of the values isn’t well-documented and you will have to do some experimentation to figure them out. There are constant values defined in the Length class, but right now I can’t seem to find where the Length class itself is documented! I see TIG is responding - likely he will know. You can get a list by typing in the Ruby Console

Length.constants

Edit: Doh! The Length class and its constants are documented in the Ruby API docs. Somehow I overlooked them before.

The base unit in SketchUp & its API is the inch.
However, as you should know in SketchUp itself you can set a model to use metric units and permutations of imperial units, including fractional.
It’s the same in the API and there are methods to find the model’s unit settings, and use inputted values in model units into API friendly format and of course converting between setting as you go…
active_model.options
so for example to get the units use:
active_model.options["UnitsOptions"]["LengthUnit"]
It returns an integer representing the type on units used.
It can also be reset using ...=1 or whatever…

The ‘lengths’ themselves are manipulated by:
https://ruby.sketchup.com/Length.html
also see:
https://ruby.sketchup.com/String.html#to_l-instance_method
and the methods to swap between units types - e.g…
https://ruby.sketchup.com/Numeric.html#to_l-instance_method

Hello, many thanks…always very kind in answering me…
Greetings
Joseph.

Hello, many thanks…
Greetings
Joseph.