Visual Basic Customization

Visual Basic Customization

Reply
Contributor
vinayan
Posts: 13
Registered: ‎05-17-2009
Message 1 of 7 (789 Views)
Accepted Solution

drawing a perpendicular from a point to line

789 Views, 6 Replies
05-17-2009 10:01 AM
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
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
Distinguished Contributor
fantum
Posts: 313
Registered: ‎12-06-2004
Message 2 of 7 (789 Views)

Re: drawing a perpendicular from a point to line

05-18-2009 08:53 AM 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
*Laurie
Message 3 of 7 (789 Views)

Re: drawing a perpendicular from a point to line

05-18-2009 03:27 PM 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
Contributor
vinayan
Posts: 13
Registered: ‎05-17-2009
Message 4 of 7 (789 Views)

Re: drawing a perpendicular from a point to line

05-28-2009 11:11 PM 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
Contributor
vinayan
Posts: 13
Registered: ‎05-17-2009
Message 5 of 7 (789 Views)

Re: drawing a perpendicular from a point to line

05-28-2009 11:13 PM in reply to: vinayan
Hi fantum,

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

thank you
Vinayan
Distinguished Contributor
fantum
Posts: 313
Registered: ‎12-06-2004
Message 6 of 7 (789 Views)

Re: drawing a perpendicular from a point to line

05-29-2009 06:02 AM 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.
Member
MakCADD
Posts: 4
Registered: ‎05-25-2013
Message 7 of 7 (424 Views)

Re: drawing a perpendicular from a point to line

05-25-2013 11:02 PM in reply to: vinayan

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.