Error in Point3d.offset when in metric environment

I use Sketchup in metric(mm) mode and am writing ruby script but there appears to be an error in the calculation of p2 from the offset of p1 in the following example

p1 = Geom::Point3d.new(0,0,0)  
p2 = Geom::Point3d.new(1000,0,0)   
v1 = p1.vector_to(p2)
panelLength = 94.488      # 2400mm in inches
v1.length = panelLength
p2 = p1.offset v1


print("p1 = ", p1, "\n")
print("v1 = ", v1, "\n")
print("p2 = ", p2, "\n")
print("panelLength= ", panelLength, "\n")

The Ruby console output appears thus:

p1= (0mm, 0mm, 0mm)
v1= (94.48818897637796, 0.0, 0.0)
p2= (2400mm, 0mm, 0mm)
panelLength= 94.48818897637796

Whereas the Point3d objects report metric values, the Vector3d objects report the internal imperial measure. This would appear to be an error.

Sketchup always uses inches internally. When reporting lengths, however, it may present them with units attached.

Looks as if the v1 variable is just reporting internal units (not a length) whereas p1 and p2 are reporting lengths in whatever units you have set in model info - mm in this case.

Confusing, perhaps, but not an error.

I’ll add that when John says “length” he is talking about the SketchUp API Length class.

See also the Numeric class which has some nice methods for handling units.

(Moved to the Developers > Ruby API category. hint hint :wink: )


You can use the API’s extensions to the Numeric classes to your advantage:

panelLength = 2400.mm

See: Numeric superclass (It’s methods are inherited by all it’s subclasses.)


Can also be done using puts() which adds a linefeed, along with a single string argument using an interpolation operator.

puts "p1 = #{p1}"
puts "v1 = #{v1}"
puts "p2 = #{p2}"
puts "panelLength= #{panelLength}"

[Notice I do not use parenthesis with puts(). This is because global methods defined in class Object, and module Kernel (which is mixed into Object,) are considered to have keyword status. This is called a style guideline. Parenthesis can still be used when the argument list is complex or spans several lines, etc. Ie, it’s not a hard and fast rule. Readability is paramount.]