relative point for line

relative point for line

Anonymous
Not applicable
308 Views
1 Reply
Message 1 of 2

relative point for line

Anonymous
Not applicable
Hello. This is very basic, but I have not found the answer that I am looing for. What is the simplest way to pick a point and have VBA create another point in relation to the one picked so you can create a line? To add a line requires another point so there should be a very simplified verson of this:

Function SetNewPoint(aPoint, distance, angle)
'This is an internal function used to create a new point relative to another
'aPoint = the point from which the new point will be located from
'distance = the distance from aPoint to the new Point
'angle = the angle from aPoint to the new point (radians) measured from the global
' x-axis with positive angles being CCW

Dim newEndPoint(3) As Double

newEndPoint(1) = aPoint(1) + distance * Cos(angle)
newEndPoint(2) = aPoint(2) + distance * Sin(angle)
newEndPoint(3) = 0

SetNewPoint = newEndPoint

End Function

Sub DrawVertLine()

Dim P1 as Variant
Dim Pnt1 as Double
Dim Pnt2 As Double
Dim Line1 As AcadLine

P1 = ThisDrawing.Utility.GetPoint(, vbCrLf & "Enter the start point of the line: ")

Pnt1(1) = P1(0): Pnt1(2) = P1(1): Pnt1(3) = 0
Pnt2 = SetNewPoint(Pnt1, 10, Pi / 2)

Set Line1 = ThisDrawing.ModelSpace.Addline(Pnt1, Pnt2)

End Sub
0 Likes
309 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Hi
I'm wondering
Why you do not use a root
function "PolarPoint"
And use an error handler to easy
find the mistakes
See the quick example
Hth

'//code start
Option Explicit
Sub DrawVertLine()
Dim pi As Double
Dim Pnt1 As Variant
Dim Pnt2 As Variant
Dim Line1 As AcadLine
pi = Atn(1) * 4
' initialize error handler
On Error GoTo Err_Control

With ThisDrawing.Utility
Pnt1 = .GetPoint(, vbCrLf & "Enter the start point of the line: ")
Pnt2 = .PolarPoint(Pnt1, pi / 2, 10)
End With
Set Line1 = ThisDrawing.ModelSpace.AddLine(Pnt1, Pnt2)

Err_Control:
MsgBox Err.Description

End Sub
'//code end
0 Likes