Enter the gpuser Subroutine
 
 
 

The gpuser subroutine prompts the user for information necessary for drawing a garden path. Enter the following code after the distance function:

' Acquire information for garden path
Private Sub gpuser()
	Dim varRet As Variant


	varRet = ThisDrawing.Utility.GetPoint( _
	 , "Start point of path: ")
	sp(0) = varRet(0)
	sp(1) = varRet(1)
	sp(2) = varRet(2)
	varRet = ThisDrawing.Utility.GetPoint( _
	 , "Endpoint of path: ")
	ep(0) = varRet(0)
	ep(1) = varRet(1)
	ep(2) = varRet(2)
	hwidth = ThisDrawing.Utility. _
	 GetDistance(sp, "Half width of path: ")
	trad = ThisDrawing.Utility. _
	 GetDistance(sp, "Radius of tiles: ")
	tspac = ThisDrawing.Utility. _
	 GetDistance(sp, "Spacing between tiles: ")
	pangle = ThisDrawing.Utility.AngleFromXAxis( _
	 sp, ep)
	totalwidth = 2 * hwidth
	plength = distance(sp, ep)
	angp90 = pangle + dtr(90)
	angm90 = pangle - dtr(90)
End Sub

In the gpuser subroutine, the line Dim varRet As Variant declares the variable varRet. Because this variable is used only in this subroutine, it can be declared here locally, instead of in the (Declarations) section.

The next line, varRet = ThisDrawing.Utility.GetPoint( , "Start point of path: "), calls the GetPoint method. The underscore in the line is intended to make a long line easier to read, and tells VBA to read the next line as if it were on the same line. You can remove the underscore by placing the code all on one line.

To access the GetPoint method, you must first go through the ThisDrawing object that represents the current drawing. After entering ThisDrawing you enter a period (.), which means that you are going to access something within that object. After you type the period, you enter Utility and another period. Once again, you are going to access something within the Utility object. Finally, enter GetPoint, which is the name of the method you are calling.

The GetPoint method takes two parameters. The first parameter is optional and won't be used. Leave the parameter blank and simply type a comma to mark its spot. The second parameter is the prompt, which is also optional. For this parameter, you entered a string prompting the user to enter the start point. The point the user enters is put into the varRet variable. The next three lines of the subroutine copy the point returned by the user into the sp array.

The endpoint is returned in the same manner.

The GetDistance method is used to obtain the half width of the path (hwidth), the tile radius (trad), and the spacing between the tiles (tspac). The GetDistance method takes two parameters. The first parameter is a base point. For this value, you supply the start point. The second parameter is the prompt, for which you provide a string prompting the user for the appropriate input. The interesting thing about the GetDistance method is that it can return either a value entered on the command line or the distance between a point selected in AutoCAD and the start point.

The subroutine goes on to calculate several variables used later in the macro. The pangle variable is set to the angle from the start point to the endpoint and is found by using the AngleFromXAxis method. The width of the path is found by multiplying the half width by two. The plength variable is set to the length of the path and is found using the distance function you entered earlier. Finally, calculate and save the angle of the path plus and minus 90 degrees in angp90 and angm90, respectively.

The following illustration shows how the variables obtained by gpuser specify the dimensions of the path.

Save your work.