Project_to_line problem

Yes.

The API defines the constant ORIGIN as a Geom::Point3d object with coordinates: [0,0,0].

should be:

ents = model.active_entities
ent = ents[0]

… BUT if the user is making the selection, then just:

ents = model.active_entities
ent = sel[0]

However, you are mixing virtual geometic helper objects and actual model drawing element objects.

A line is a geometric helper which is virtual. It passes through two points but is infinite in length. It has no ends. The model entities collection does not have lines. Lines are only for virtual geometric work in memory.

The SketchUp entities collection has edge objects. They have finite length. Each has a start vertex, and an end vertex.

Sketchup::Vertex objects are in the model. But they are not Geom::Point3d objects. You can get a Geom::Point3d equivalent from a vertex object, via:

vertex = edge.start
vertex.class
>> Sketchup::Vertex
start_point = vertex.position()
start_point.class
>> Geom::Point3d

Ok so, say your user has selected an edge object:

ents = model.active_entities
ent = model.selection[0]
if ent.is_a?(Sketchup::Edge)
  ORIGIN.on_line?( [ent.start.position, ent.end.position] )
end

http://www.sketchup.com/intl/en/developer/docs/ourdoc/point3d#on_line?

If that test is true, the test point is on the line of the edge, but may be outside the vertices of the edge. So test if the sum of the distances from the test point to the edge’s end points are equal to the edge’s length. If true the test point is somewhere along the edge. If false, the test point is outside the edge.

ent.length == ORIGIN.distance(ent.start.position)+ORIGIN.distance(ent.end.position)

http://www.sketchup.com/intl/en/developer/docs/ourdoc/point3d#distance


ALSO > How to properly quote code in the forums