# How to find an edge from a Point3D?

I noticed PickHelper and InputPoint can be used to find an edge from screen coordinates.

But is there a good way to find an edge in the scene by Ruby script from a global coordinate (Point3D)?

I mean something more elegant than traversing the whole scene in Ruby, finding all edges, and doing all 3D math in Ruby (slow…) to see whether the specified point is located on or near any edge.

What I am trying to achieve is to have components (which are being created via Ruby script) automatically align themselves to an edge if they were created on (or near) an edge.

Edit: topic sounds similar to this one, but is not the same. I do not need to re-align on future moves, and my components are not glued to faces. I am just dealing with bare edges.

I am indeed working on a similar problem but Iv’e already past the “picking on or near” problem. I use PickHelper.boundingbox_pick. It’s seem to be the only way to pick without screen coordinates. You just have to define “near” by the size of the box.

Thanks Barry - that sounds like it should do!

A custom tool can handle the “onLButtonDown” as follows:

``````def onLButtonDown(flags, x, y, view)
pickhelper = view.pick_helper(x,y)
count = pickhelper.do_pick(x, y)
best_picked = pickhelper.best_picked
@entity_path_list = pickhelper.path_at(0)
end
``````

The X and Y coordinates are given to the pick helper method to analyze what was clicked. If an ungrouped edge was clicked, then you could obtain 3D coordinates of the edge with vertices from “best_picked”.

If the edge is buried in a series of nested grouped objects, then “@entity_path_list” will contain an array of drawing elements containing the path to the edge. The edge’s vertex positions are in local coordinates and you have to apply the transformations of all the grouped objects to obtain the positions in world coordinates.

Thanks Bruce. But my issue is that in my case there is no tool and no user interaction. I am initiating all from code and starting with world coordinates. But Barry’s approach should work.