Huh? Units? WTH?
-
So, I have this code:
def create_entities(data, container)
a = data["a"].to_l w = data["w"].to_l h = data["h"].to_l pts = [[0,0,0], [a,0,0], [a,w,0], [0,w,0], [0,0,0]] base = container.add_face pts
Obviously, that's not the whole thing. It makes a box eventually, based on the points defined above.
Now, I want to alter the box to mae one side shorter than the other.
The default Length "a" is 1000mm. When I replace point [a,0,0] with [a-20,0,0] I get a weird result. I expect a-20 to be 980mm, but I end up with a side that is 492mm, which implies Sketchup is taking off 20 inches, not mm. How do I tell it to read all units as mm? I am using the Engineering (mm) template if that makes any difference.
Any help appreciated.
Regards,
Cathal
-
If '
a
' is in mm and you usea-20
you are taking of 20" !
Usea-20.mm
Raw numbers are assumed to be in inches ALWAYS! -
Make use of the Length class, and the extended method of String and Numberic to let SU handle the units. Remember that SU uses inches internally at all time. Units are presented to the user in the correct format using the assisting methods.
Length class: http://code.google.com/apis/sketchup/docs/ourdoc/length.html
Numeric class: http://code.google.com/apis/sketchup/docs/ourdoc/numeric.html
String class: http://code.google.com/apis/sketchup/docs/ourdoc/string.htmlKeep track of whether your object is a Float or Length - as that matters when the number is outputted as string to the user.
-
Advertisement