- 打开 ThisDrawing 的代码(如果尚未打开)。
- 更新 Declarations 部分的下列行:
Public trad As Double ' 已更新
Public tspac As Double ' 已更新
Public tsides As Integer ' 新增
Public tshape As String ' 新增
因为窗体中的代码要访问 trad 和 tspac,所以需要更新它们的定义使其成为公有变量。私有变量仅在其被定义的模块中可用,因此需要将私有变量变为公有。此外,已经添加表示多边形瓷砖边数的 tsides,和表示用户选择的瓷砖形状(圆形或多边形)的tshape。
- 转到 gpuser 子例程。删除包含瓷砖的半径和瓷砖之间间距的两行(因为这些信息现在来自窗体),即:
trad = ThisDrawing.Utility. _
GetDistance(sp, "Radius of tiles: ")
tspac = ThisDrawing.Utility. _
GetDistance(sp, "Spacing between tiles: ")
- 添加用于加载和显示窗体的行。在步骤 3 中删除行的位置处添加下列行:
Load gpDialog
gpDialog.Show
- 在绘制圆形瓷砖或多边形瓷砖的代码文件的末尾添加子例程:
' 用指定的形状绘制瓷砖
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
' 基于要绘制的形状类型来控制不同情况
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
该子例程使用 Select Case 语句基于要绘制的形状类型来控制程序的不同情况。tshape 变量用于确定形状类型。
- 下一步,转到 drow 子例程。找到下面一行所出现的两处位置:
Set cir = ThisDrawing.ModelSpace.AddCircle(pltile, trad)
DrawShape (pltile) ' 已更新