Units for Transformation in inches?


#1

My model uses mm as unit of measure. I am moving an instance of a component using the transform! function, for example as follows:

 if entity.visible? then 
   new_transformation = Geom::Transformation.new([User_Input,0,0])
  entity.transform! new_transformation
end

In the above, “User_input” is a value entered, in mm, by the user via a UI.inputbox. If the user enters “100”, this is translated to 2540 mm in my model, implying that despite the length units set in my model the Transformation is based in inches.

I can work around this by defining:

def mm(inchesIn)
mmOut=inchesIn/25.4
end

and substituting:

new_transformation = Geom::Transformation.new([mm(100),mm(0),mm(0)])

I have already tried TIG’s setup:

model.options[“UnitsOptions”][“LengthUnit”]=2
model.options[“UnitsOptions”][“LengthPrecision”]=1
model.options[“UnitsOptions”][“SuppressUnitsDisplay”]=false
model.options[“UnitsOptions”][“LengthFormat”]=0
model.options[“UnitsOptions”][“LengthSnapEnabled”]=false

it does not seem to make any difference.

How can I set the units to mm?


#2

Everything “under the hood” of SketchUp is in inches. This also means in Ruby too.

However, the UI.inputbox is special. It can automatically convert to and from model units transparently (the user notices nothing out of the ordinary.) The trick is to convert the float to a Length class object before stuffing it into the inputbox field. It will automatically be displayed in model units. Then it will be automatically returned in the array of return values, as a Length instance in inches.

Required Reading is Thomas Thomassen’s blog post:

:bulb:


#3

Thank you very much Dan, exactly what I needed