How to find nearest start/end point of the selected line?

How to find nearest start/end point of the selected line?

mucip
Collaborator Collaborator
1,347 Views
4 Replies
Message 1 of 5

How to find nearest start/end point of the selected line?

mucip
Collaborator
Collaborator

Hi,

I am looking to add arrowHead to selected line but I do not want to use Leader unfortunatelly.

I saw a lisp in this forms which can select a line and put a solid arrow to start or end point of the selected line. But lisp code undersatand that finding closest edge of the line from select point.

I want to do same thing with VBA. I can select the line but how can I understand if I close to start point or end point of the line while selecting line?

 

Regards,

Mucip:)

0 Likes
Accepted solutions (2)
1,348 Views
4 Replies
Replies (4)
Message 2 of 5

Ed__Jobe
Mentor
Mentor
Accepted solution

You can use the following function to get the distance between (the picked point and the start point) and (the picked point and the end point) and compare which is smaller.

Public Function XYZDistance(Point1 As Variant, Point2 As Variant) As Double
    On Error GoTo Err_Control
    'Returns the distance between two points
    Dim dblDist As Double
    Dim dblXSl As Double
    Dim dblYSl As Double
    Dim dblZSl As Double
    Dim varErr As Variant
    On Error GoTo Err_Control
    'Calc distance
    dblXSl = (Point1(0) - Point2(0)) ^ 2
    dblYSl = (Point1(1) - Point2(1)) ^ 2
    dblZSl = (Point1(2) - Point2(2)) ^ 2
    dblDist = Sqr(dblXSl + dblYSl + dblZSl)
    'Return Distance
    XYZDistance = dblDist
Exit_Here:
    Exit Function
Err_Control:
    Select Case Err.Number
    'Add your Case selections here
    'Case Is = 1000
        'Handle error
        'Err.Clear
        'Resume Exit_Here
    Case Else
        MsgBox Err.Number & ", " & Err.Description, , "XYZDistance"
        Err.Clear
        Resume Exit_Here
    End Select
End Function

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 5

mucip
Collaborator
Collaborator

Hi,

I use below command to set lines or one single line,

filterType(0) = 0
filterData(0) = "line"

Dim ssetObj As AcadSelectionSet
Set ssetObj = ThisDrawing.SelectionSets.add("PP1")

How can I get the select point of the select event. I may use below command but I can not select the entire line, can I?

thePt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Tablonun Yerini Seçin...")

 

 

Regards,

Mucip:)

0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor
Accepted solution

You use GetEntity():

 

Dim ent As AcadEntity

Dim line As AcadLine

Dim pt As Variant  '' This is where the mouse clicked when an entity is selected

On Error Resume Next

ThisDrawing.Utility.GetEntity(ent, pt, vbCr & " Select a LINE:"

If Not ent Is Nothing Then

  If TypeOf ent Is AcadLine Then

    Set line = ent

    '' Now you have a line and a point where the mouse is clicked, which is very close to the line,

    '' depending on how big the pick box is, but you can certainly use to calculate its distance to

    '' the selected line's start/end point to determine which end is closer to the picked point

  End If

End If

 

HTH

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 5

mucip
Collaborator
Collaborator

Hi,

Thanks a lot gentilmen...

 

Regards,

Mucip:)

0 Likes