Ruby console units
-
Hi!
I'm sure this is a newbie question, probably asked many times before, but i searched for it on the forum and i couldn't find it.
I'm very new to ruby (less than a week) and i have some experience with sketch-up(hobby, designing furniture for my new apartment).
So here goes nothing. What unit does sketch-up use internally? For example, if i use the line = entities.add_line point1,point2 command, the coordinates for the points are considered inches, even with my template set to cm.
It's not a big deal, but i plan to write an export to sketchup tool(more like an import to sketchup plugin) for the company's software(it uses the metric system). Do i have to use the numeric.cm & co commands or can i just set the unit to whatever i want?
Thanks -
Yup, SketchUp's internal units are inches.
Check out the enhancements SketchUp has done to the numeric class to help convert easier between units.
http://code.google.com/apis/sketchup/docs/ourdoc/numeric.html
There is also a
parse_length
command available that will help parse a string.Sketchup.parse_length("50m")
though I think Adam just recently noted a bug with that method. I already forgot what it was though.So if the user enters "10" you can parse that and SU will turn it into a number in inches equal to 10 nodel units. If the model is in meters, it will return 393.700787401575 (inches). Then take that number and run it though
Sketchup.format_length(393.700787401575)
to format inches into model units -10.0m
Try this exercise to see how to take what the user enteres, turn it into inches for SketchUp to work with, then back into meters to display to the user again.
len = Sketchup.parse_length("10") puts len len = Sketchup.format_length(len) puts len
-
Thank you Chris.
Well since it's in inches i'm going to have to use the .mm type of commands. I don't care/need to know what template the user uses, it's just operations would have been simpler.
Advertisement