turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Close

Visual Basic Customization

- Autodesk Community
- >
- AutoCAD Customization
- >
- Visual Basic Customization
- >
- drawing a perpendicular from a point to line

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

788 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

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

Solved! Go to Solution.

Solved! by *Laurie. See the answer in context.

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

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

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

Dim p2(0 To 2) As Double: p2(0) = 2#: p2(1) = -1#

ThisDrawing.ModelSpace.AddLine p1, p2

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-18-2009 03:27 PM in reply to:
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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

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

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

thank you

Vinayan

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

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.

I had gathered as much which was why I gave you exactly what you asked for rather than doing your homework for you.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

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

Search This Board

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Post to the Community

Have questions about Autodesk products? Ask the community.

The Knowledge Network

Access a broad range of knowledge to help get the most out of your products and services.

Download & Installation

Getting your Software

Downloads & Upgrades

Serial Numbers & Product Keys

Installation & Licensing

Activation & Registration

Network License Administration

Subscription Management

Sign In / Create Account

Maintenance Subscription Help

Desktop Subscription Help

Cloud Service Subscription FAQ

Announcements

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.

- Privacy | Legal Notices & Trademarks | Report Noncompliance | Site map | © Copyright 2014 Autodesk Inc. All rights reserved

Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Please see the Autodesk Creative Commons FAQ for more information.