Don't know if this helps but...
I did somthing similar but decided that I wanted to
loop through the smallest sset poosible so starting from the point that I
picked, I created a selection set with a crossing window that began one unit
below and to the left and ended one unit to the right and above. If something
was found, check the distance on the entites (unless only one was found). If
nothing was found, add one more unit to each of the points. Keep repeating until
results is found or offset reaches a preset number (a max distance value). Why
am I blabbering?? Here is the code, see if it helps....
Public Function FindNearestEntity(ByVal Point1 As
Variant, ByVal MaxDistance As Double, Optional LayerPattern As String = "*") As
AcadEntity
Dim sst_items As AcadSelectionSet
Dim ent_retrn
As AcadEntity
Dim dbl_offst As Double
Dim pnt_lleft(2) As
Double
Dim pnt_urght(2) As Double
Dim dxf_codes(7) As
Integer
Dim dxf_value(7) As Variant
Dim dbl_prevs As
Double
Dim dbl_distn As Double
Dim pnt_nears As
Variant
Dim ent_check As AcadEntity
dxf_codes(0)
= 8
dxf_value(0) = LayerPattern
dxf_codes(1) = -4
dxf_value(1) = "<OR"
dxf_codes(2) = 0
dxf_value(2) =
"LINE"
dxf_codes(3) = 0
dxf_value(3) = "CIRCLE"
dxf_codes(4) = 0
dxf_value(4) = "ARC"
dxf_codes(5) =
0
dxf_value(5) = "POLYLINE"
dxf_codes(6) = 0
dxf_value(6) = "LWPOLYLINE"
dxf_codes(7) = -4
dxf_value(7) =
"OR>"
dbl_offst = 2
On Local Error Resume Next
ThisDrawing.SelectionSets("FindNearest").Delete
Set sst_items =
ThisDrawing.SelectionSets.Add("FindNearest")
On Local Error GoTo
0
Do While dbl_offst < MaxDistance
pnt_lleft(0) = Point1(0) - dbl_offst
pnt_lleft(1) =
Point1(1) - dbl_offst
pnt_urght(0) = Point1(0) +
dbl_offst
pnt_urght(1) = Point1(1) +
dbl_offst
sst_items.Select
acSelectionSetCrossing, pnt_lleft, pnt_urght, dxf_codes,
dxf_value
If sst_items.Count = 1
Then
Set ent_retrn =
sst_items.Item(0)
Exit
Do
ElseIf sst_items.Count > 0
Then
'process each entity to see which one is
actually closer....
For Each ent_check In
sst_items
pnt_nears =
tjnLSP.ClosestPointTo(ent_check, Point1,
False)
If Not
tjnARR.ArrayIsEmpty(pnt_nears)
Then
dbl_distn =
tjnCAL.Distance(Point1,
pnt_nears)
If
dbl_prevs = 0
Then
Set
ent_retrn =
ent_check
dbl_prevs = dbl_distn
ElseIf dbl_distn < dbl_prevs
Then
Set
ent_retrn =
ent_check
dbl_prevs = dbl_distn
End If
End
If
pnt_nears =
Empty
Next
Exit Do
End If
dbl_offst = dbl_offst
+ 2
Loop
Set FindNearestEntity = ent_retrn
End
Function
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Thanks
for reply, but I know how to find the distance between a point and a line. I
was just looking for a simpler way to find the closest line to a
point.