Now that you have acquired the location and width of the path, you can draw its outline. Add the following code below the gpuser subroutine:
' Draw outline of path
Private Sub drawout()
Dim points(0 To 9) As Double
Dim pline As AcadLWPolyline
Dim varRet As Variant
varRet = ThisDrawing.Utility.PolarPoint( _
sp, angm90, hwidth)
points(0) = varRet(0)
points(1) = varRet(1)
points(8) = varRet(0)
points(9) = varRet(1)
varRet = ThisDrawing.Utility.PolarPoint( _
varRet, pangle, plength)
points(2) = varRet(0)
points(3) = varRet(1)
varRet = ThisDrawing.Utility.PolarPoint( _
varRet, angp90, totalwidth)
points(4) = varRet(0)
points(5) = varRet(1)
varRet = ThisDrawing.Utility.PolarPoint( _
varRet, pangle + dtr(180), plength)
points(6) = varRet(0)
points(7) = varRet(1)
Set pline = ThisDrawing.ModelSpace. _
AddLightWeightPolyline(points)
End Sub
This subroutine draws the outline of the path using the AddLightweightPolyline method. This method takes one parameter: an array of points that make up the polyline. You must find all the points that make up the polyline object and place them into an array in the order they are to be drawn. For this polyline, the points needed are the corners of the path.
To find the corners of the path, use the PolarPoint method. This method finds a point that is a given angle and distance from a base point. Begin with the start point (sp) and find the first corner of the path, working in a counterclockwise direction. This corner will be at a distance of half the width of the path (hwidth) and at -90 degrees from the path angle. Because you want to draw a closed rectangle for the path, this point becomes the first and last point in the array. Hence, the X and Y coordinates returned from the PolarPoint method are moved into the first and last positions in the points array.
The remaining corners of the path are found in the same manner using the length and width of the path (plength and width), and the angle of the path. Every time the PolarPoint method is called, the coordinates returned (varRet) are copied into the points array.
Once all the corners have been identified in the points array, the AddLightweightPolyline method is called. Notice that this method is called from the ModelSpace object. If you were to run this macro, you would also notice that the polyline is not yet visible in AutoCAD. The polyline will not become visible until you update the display, which you will do later.