| Author |
Message |
Oberer
Guest
|
Posted:
Wed Jan 05, 2005 11:45 pm Post subject:
Draw Perpendicular Lines - Code help requested |
|
|
I'd like to draw a line that's perpendicular to a selected line with a constant length.
The code I have now does all of the above, except for the constant length.
"A picture is worth a thousand words" certainly applies here. Please look at the attachment to see what I'd like the code to do (in yellow). I'm currently getting the shorter, different length cyan lines.
i've search thru vba, the NG, and google for ways to modify a line's length, and can't find it. TIA!
| Code: |
Public Sub PerpLine()
Dim line As AcadLine
Dim pt As Variant
Dim xline As AcadXline
Dim oLateralTop As AcadLine
Dim vPointSelected As Variant
Dim pt2, ang As Double, pi As Double, vMidPt As Variant
Dim iOsnapMode As Integer
Dim oUtil As AcadUtility
pi = Atn(1) * 4
iOsnapMode = ThisDrawing.GetVariable("OSMODE")
ThisDrawing.SetVariable "OSMODE", 1
Set oUtil = ThisDrawing.Utility
oUtilGetEntity line, pt, "Select a lateral: "
' SELECT ENDPOINT TO ANNOTATE
vPointSelected = oUtil.GetPoint(, "Select a point: ")
pt = vPointSelected
'-this is where i'm screwing up. if i don't adjust this point
'somehow, i end up with a zero length line...
pt(0) = pt(0) + 3
pt(1) = pt(1) + 3
ang = oUtil.AngleFromXAxis(line.StartPoint, line.EndPoint)
pt2 = oUtil.PolarPoint(pt, ang - pi / 2, 1)
Set xline = ThisDrawing.ModelSpace.AddXline(pt, pt2)
pt2 = xline.IntersectWith(line, acExtendBoth)
Set oLateralTop = ThisDrawing.ModelSpace.AddLine(pt, pt2)
xline.Delete
' get midpoint of newly created line
vMidPt = MidPoint(oLateralTop.StartPoint, oLateralTop.EndPoint)
' move new line from it's midpoint to the selected endpoint
oLateralTop.Move vMidPt, vPointSelected
ThisDrawing.SetVariable "OSMODE", iOsnapMode
Set oUtil = Nothing
Set line = Nothing
Set xline = Nothing
Set oLateralTop = Nothing
End Sub
|
Message was edited by: Oberer
|
|
| Back to top |
|
 |
Jeff Mishler
Guest
|
Posted:
Thu Jan 06, 2005 12:16 am Post subject:
Re: Draw Perpendicular Lines - Code help requested |
|
|
You want something like this:
Sub testme()
Dim pi As Double
Dim line As AcadLine
Dim pt1, pt2, pt3
Dim oUtil As AcadUtility
Dim osmode As Integer
Dim ang As Double
pi = Atn(1) * 4
Set oUtil = ThisDrawing.Utility
oUtil.GetEntity line, pt1, "Select line: "
osmode = ThisDrawing.GetVariable("osmode")
ThisDrawing.SetVariable "Osmode", 1
pt1 = oUtil.GetPoint(, "Select end for lateral: ")
ThisDrawing.SetVariable "Osmode", osmode
ang = line.Angle
pt2 = oUtil.PolarPoint(pt1, ang + (pi / 2), 3)
pt3 = oUtil.PolarPoint(pt1, ang - (pi / 2), 3)
ThisDrawing.ModelSpace.AddLine pt2, pt3
End Sub
--
Jeff
check out www.cadvault.com
"Oberer" <nospam@address.withheld> wrote in message
news:30223427.1104950735202.JavaMail.jive@jiveforum2.autodesk.com...
| Quote: | I'd like to draw a line that's perpendicular to a selected line with a
constant length.
The code I have now does all of the above, except for the constant length.
"A picture is worth a thousand words" certainly applies here. Please look
at the attachment to see what I'd like the code to do (in yellow). I'm
currently getting the shorter, different length cyan lines.
i've search thru vba, the NG, and google for ways to modify a line's
length, and can't find it. TIA!
| Code: |
Public Sub PerpLine()
Dim line As AcadLine
Dim pt As Variant
Dim xline As AcadXline
Dim oLateralTop As AcadLine
Dim vPointSelected As Variant
Dim pt2, ang As Double, pi As Double, vMidPt As Variant
Dim iOsnapMode As Integer
Dim oUtil As AcadUtility
pi = Atn(1) * 4
iOsnapMode = ThisDrawing.GetVariable("OSMODE")
ThisDrawing.SetVariable "OSMODE", 1
Set oUtil = ThisDrawing.Utility
oUtilGetEntity line, pt, "Select a lateral: "
' SELECT ENDPOINT TO ANNOTATE
vPointSelected = oUtil.GetPoint(, "Select a point: ")
pt = vPointSelected
'-this is where i'm screwing up. if i don't adjust this point
'somehow, i end up with a zero length line...
pt(0) = pt(0) + 3
pt(1) = pt(1) + 3
ang = oUtil.AngleFromXAxis(line.StartPoint, line.EndPoint)
pt2 = oUtil.PolarPoint(pt, ang - pi / 2, 1)
Set xline = ThisDrawing.ModelSpace.AddXline(pt, pt2)
pt2 = xline.IntersectWith(line, acExtendBoth)
Set oLateralTop = ThisDrawing.ModelSpace.AddLine(pt, pt2)
xline.Delete
' get midpoint of newly created line
vMidPt = MidPoint(oLateralTop.StartPoint, oLateralTop.EndPoint)
' move new line from it's midpoint to the selected endpoint
oLateralTop.Move vMidPt, vPointSelected
ThisDrawing.SetVariable "OSMODE", iOsnapMode
Set oUtil = Nothing
Set line = Nothing
Set xline = Nothing
Set oLateralTop = Nothing
End Sub
|
Message was edited by: Oberer
|
|
|
| Back to top |
|
 |
Oberer
Guest
|
Posted:
Thu Jan 06, 2005 12:46 am Post subject:
Re: Draw Perpendicular Lines - Code help requested |
|
|
Jeff,
Once again, your help is greatly appreciated. This is exactly what I was looking for!
|
|
| Back to top |
|
 |
Jeff Mishler
Guest
|
Posted:
Thu Jan 06, 2005 1:40 am Post subject:
Re: Draw Perpendicular Lines - Code help requested |
|
|
Glad I can be of help!
--
Jeff
check out www.cadvault.com
"Oberer" <nospam@address.withheld> wrote in message
news:18915558.1104954430239.JavaMail.jive@jiveforum2.autodesk.com...
| Quote: | Jeff,
Once again, your help is greatly appreciated. This is exactly what I was
looking for! |
|
|
| Back to top |
|
 |
Oberer
Guest
|
Posted:
Thu Jan 06, 2005 1:41 am Post subject:
Re: Draw Perpendicular Lines - Code help requested |
|
|
If anyone else is interested, I updated the line selection to calculate the endpoint to annotate:
Thanks again!
| Code: |
' SELECT LATERAL
oUtil.GetEntity oLateral, vPoint1, "Select lateral near setback: "
' calculate which endpoint to use
If getDistance(vPoint1, oLateral.StartPoint) > getDistance(vPoint1, oLateral.EndPoint) Then
vPoint1 = oLateral.EndPoint
Else
vPoint1 = oLateral.StartPoint
End If
|
|
|
| Back to top |
|
 |
|
|
|
|