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

drawing a perpendicular from a point to line

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
vinayan
2381 Views, 6 Replies

drawing a perpendicular from a point to line

Hello,

I have a line which is at (0,0) and (2,2). I need to draw a perpendicular to this line from point(1,0). Could someone help me with the VBA code for this?

Thanks in advance
Vinayan
6 REPLIES 6
Message 2 of 7
fantum
in reply to: vinayan

Dim p1(0 To 2) As Double: p1(0) = 1#: p1(1) = 0#
Dim p2(0 To 2) As Double: p2(0) = 2#: p2(1) = -1#
ThisDrawing.ModelSpace.AddLine p1, p2
Message 3 of 7
Anonymous
in reply to: vinayan

Hi Vinayan,

Here is a general solution to your query. All it requires is that the
initial line has already been drawn.

You could adjust this code to solve your initial problem, just by making
the ends of the new line to be 1,0 and .5,.5


Sub Test()
On Error GoTo ErrorHandler
Dim p1(0 To 2) As Double
Dim p2(0 To 2) As Double
Dim oLine As AcadLine
Dim oLine2 As AcadLine
Dim dAngle As Double
Dim oEnt As AcadEntity
Const HalfPi = 1.5707963267949
ThisDrawing.Utility.GetEntity oEnt, p1
If TypeOf oEnt Is AcadLine Then
Set oLine = oEnt
dAngle = oLine.Angle + HalfPi
v = ThisDrawing.Utility.GetPoint(, "Select the start point")
p1(0) = v(0)
p1(1) = v(1)
v = ThisDrawing.Utility.PolarPoint(p1, dAngle, 10)
p2(0) = v(0)
p2(1) = v(1)
Set oLine2 = ThisDrawing.ModelSpace.AddLine(p1, p2)
v = oLine.IntersectWith(oLine2, acExtendBoth) ' Note the options here
p2(0) = v(0)
p2(1) = v(1)
oLine2.EndPoint = p2
oLine2.Update
Else

End If
Exit Sub
ErrorHandler:
MsgBox "Unable to complete Sub 'Test' due to" & vbCrLf & Err.Description
Err.Clear

End Sub ' Test




Regards,


Laurie Comerford
VBAChallenger wrote:
> Hello, I have a line which is at (0,0) and (2,2). I need to draw a
> perpendicular to this line from point(1,0). Could someone help me with
> the VBA code for this? Thanks in advance Vinayan
Message 4 of 7
vinayan
in reply to: vinayan

Hi Laurie,

I am excited to get a reply from you. Your answers have always been straight to the point..I was really wondering how to get this polarpoint thing to work in my code but was not sure..this solves my problem..

Thank you
Vinayan
Message 5 of 7
vinayan
in reply to: vinayan

Hi fantum,

Thanks for the reply..but i was looking for another logic

thank you
Vinayan
Message 6 of 7
fantum
in reply to: vinayan

> i was looking for another logic

I had gathered as much which was why I gave you exactly what you asked for rather than doing your homework for you.
Message 7 of 7
MakCADD
in reply to: vinayan

draw again the line, then move it to the point, rotate to 90 degree, find the intersection, trim it

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

Post to forums  

Autodesk Design & Make Report

”Boost