Length conversion problems
-
Hi, all!
As a first attempt at Ruby scripting in Sketchup 8.0, I have tried to emulate TBD's moveIT, but with one difference : the reference point is the group's or component's bounding box center, not the lower left corner.
The logic is very simple and the thing works, but after the move the object is never quite at the intended position. There is always a slight difference. I suppose that it is a unit conversion problem, as I use meters and I believe that SU internally uses inches.
How can I fix that? Thanks in advance,
ThierryP.S: The script is attached if you want to look at it.
-
When you get the point's p.x etc it's returned as a Length - it's in inches.
However the UI displays in an input box dialog in the current SKP's units, which could be inches or could be meters or whatever...
To 'display' it in say the Ruby Console in meters use p.x.to_m - it's then a Float [in meters].
When you type a value in an input dialog in 'meters' it will get converted discreetly into inches for Sketchup to use internally anyway...
You don't need to worry about changing units in your code...
The fact that the returned value is internally in 'inches' doesn't matter - the Length class allows you to manipulate it as if it were a Float and say divide by 2, or adding a value in inches to one 'seen' in meters in of no consequence.By the way... .rb files can be attached directly without zipping them...
-
Thanks very much, TIG
Advertisement