Question

Hi all

I am trying to get the distance from one 3D point object to a line. This is my code:

line_x = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(1,0,0)]
a = [10,11,0]
distance_x = a.distance_to_line line_x
puts distance_x

This is output in Sketchup ruby console.

11"

11"

I try distance_x.typename , but it got error :undefined method `typename' for 11.0:Length

I think output of distance_to_line is a number. Why i got double of result while i just call puts in one time.
Please help me, thanks

Was it helpful?

Solution

Array.distance_to_line returns a Length.

line_x = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(1,0,0)]
[Point3d(0, 0, 0), Vector3d(1, 0, 0)]
a = [10,11,0]
[10, 11, 0]
distance_x = a.distance_to_line line_x
11.0
distance_x.class
Length

Yes, the docs aren't very clear on the return type.

OTHER TIPS

I've used SketchUp before, but not with Ruby scripting. I've just tried it out now, and I see the console outputs the return value each time you enter a line (in addition to any puts output). But I can't reproduce exactly what you're seeing.

If I enter each line one at a time, I get 11.0 after the second last line and then this after the last line:

11"
nil

The 'nil' is what #puts actually returns.

If I save the script in a text editor and load it into SketchUp, I instead get this:

11"
true

'True' is the return value when 'there are no syntax errors in the file' according to the SketchUp documentation.

But as I said, I can't reproduce exactly what you're seeing.

What do you see if you change the last line to just 'distance_x' (delete the word 'puts')? For me, this just returns the value '11.0'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top