Update the Existing Code

AutoCAD ActiveX

 
Update the Existing Code
 
 
 

Now that you have created a dialog box, you can modify and add code.

To modify the existing code

  1. Open the code for ThisDrawing, if it is not already open.
  2. Update the following lines in the Declarations section:
    Public trad As Double       ' Updated
    Public tspac As Double      ' Updated
    Public tsides As Integer    ' Add
    Public tshape As String     ' Add

    Because the code in the form accesses trad and tspac, you update their definitions to make them public. Private variables are available only in the module in which they are defined, so the variables need to be changed to public. Additionally, you have added tsides for the number of polygon tile sides and tshape for the user's choice of tile shape, which is either circle or polygon.

  3. Go to the gpuser subroutine. Remove the two lines that obtain the radius of the tiles and the spacing between the tiles, because this information comes from the form. Specifically, remove the following:
    trad = ThisDrawing.Utility. _
     GetDistance(sp, "Radius of tiles: ")
    tspac = ThisDrawing.Utility. _
     GetDistance(sp, "Spacing between tiles: ")
  4. Add the lines that load and display the form. Add the following lines in place of the lines removed in step 3:
    Load gpDialog 
    gpDialog.Show 
  5. Add a subroutine to the end of the code file that draws either the circular tiles or the polygon tiles:
    'Draw the tile with the designated shape
    Sub DrawShape(pltile)
     Dim angleSegment As Double
     Dim currentAngle As Double
     Dim angleInRadians As Double
     Dim currentSide As Integer
     Dim varRet As Variant
     Dim aCircle As AcadCircle
     Dim aPolygon As AcadLWPolyline
     ReDim points(1 To tsides * 2) As Double
     'Branch based on the type of shape to draw
     Select Case tshape
     Case "Circle"
     Set aCircle = ThisDrawing.ModelSpace. _
     AddCircle(pltile, trad)
     Case "Polygon"
     angleSegment = 360 / tsides
     currentAngle = 0
     For currentSide = 0 To (tsides - 1)
     angleInRadians = dtr(currentAngle)
     varRet = ThisDrawing.Utility.PolarPoint(pltile, _
     angleInRadians, trad)
     points((currentSide * 2) + 1) = varRet(0)
     points((currentSide * 2) + 2) = varRet(1)
     currentAngle = currentAngle + angleSegment
     Next currentSide
     Set aPolygon = ThisDrawing.ModelSpace. _
     AddLightWeightPolyline(points)
     aPolygon.Closed = True
     End Select
    End Sub

    This subroutine uses a Select Case statement to branch control of the program based on the type of shape to draw. The tshape variable is used to determine the type of shape.

  6. Next, go to the drow subroutine. Find the two occurrences of the following line:
    Set cir = ThisDrawing.ModelSpace.AddCircle(pltile, trad)

    Change these lines to draw the appropriate shape tile, as follows:

    DrawShape (pltile)       ' Updated