VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to find pt4 point with vba

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Mesut_Akcan
1136 Views, 1 Reply

How to find pt4 point with vba

How to find pt4 point or length of L line with vba.

pt3 is any coordinate point clicked.

question picturequestion picture 

Mesut Akcan - Emekli Teknik Öğretmen
Blog Sayfam -- Youtube Kanalım -- LinkedIn
Tags (4)
1 REPLY 1
Message 2 of 2
Mesut_Akcan
in reply to: Mesut_Akcan

I found a solution to my own question.

 

Sub Test_pt4()
pi = 3.1415926535898
With ThisDrawing
    pt1 = .Utility.GetPoint(, "First point:")
    pt2 = .Utility.GetPoint(pt1, "Second point:")
    Set objLine = .ModelSpace.AddLine(pt1, pt2)
    pt3 = .Utility.GetPoint(pt2, "Third point:")
    
    ang = .Utility.AngleFromXAxis(pt1, pt3)
    x = pt3(0) - pt1(0) 'X
    y = pt3(1) - pt1(1) 'Y
    
    L = Sin(ang - objLine.Angle) * Sqr(x * x + y * y)
' Alternative
'    L = (y - (Tan(objLine.Angle) * x)) * Cos(objLine.Angle)
    
    pt4 = .Utility.PolarPoint(pt2, objLine.Angle + pi / 2, L)

    .ModelSpace.AddLine pt2, pt4
    .ModelSpace.AddLine pt3, pt4
End With
End Sub

but my main goal was to draw a rectangle with 3 points

I reached my goal

codes below

Sub Rectangle3points()
'Mesut Akcan
'05/08/2019
Dim pt1, pt2, pt3, pt4, points(0 To 7) As Double
Dim ang, pi, t3, x, y, L
Dim pl As AcadLWPolyline
Dim objLine As AcadLine
pi = 3.1415926535898
With ThisDrawing
    pt1 = .Utility.GetPoint(, "First point:")
    pt2 = .Utility.GetPoint(pt1, "Second point:")
    Set objLine = .ModelSpace.AddLine(pt1, pt2)
    objLine.color = acGreen
    objLine.Highlight True
        
    t3 = .Utility.GetPoint(pt2, "Third point:")
    
    ang = .Utility.AngleFromXAxis(pt1, t3)
    x = t3(0) - pt1(0)
    y = t3(1) - pt1(1)
    
    L = Sin(ang - objLine.Angle) * Sqr(x * x + y * y)
'   Alternative
'   L = (y - (Tan(objLine.Angle) * x)) * Cos(objLine.Angle)
    
    pt3 = .Utility.PolarPoint(pt2, objLine.Angle + pi / 2, L)
    pt4 = .Utility.PolarPoint(pt3, objLine.Angle + pi, objLine.Length)
    
    objLine.Delete
    points(0) = pt1(0): points(1) = pt1(1) '1. point X,Y
    points(2) = pt2(0): points(3) = pt2(1) '2. point
    points(4) = pt3(0): points(5) = pt3(1) '3. point
    points(6) = pt4(0): points(7) = pt4(1) '4. point
    
    Set pl = .ModelSpace.AddLightWeightPolyline(points)
    pl.Closed = True
End With
End Sub
Mesut Akcan - Emekli Teknik Öğretmen
Blog Sayfam -- Youtube Kanalım -- LinkedIn

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost