Sub polygon()
'以下语句绘制正多边形
Dim num As Integer
Dim pnt As Variant
Dim lpnt As Variant
num = ThisDrawing.Utility.GetInteger("请选择正多边形的边数:")
Dim fpnt As Variant
fpnt = ThisDrawing.Utility.GetPoint(, "请选择正多边形的起点:")
Dim leng As Double
leng = ThisDrawing.Utility.GetDistance(fpnt, "请选择正多边形的边长:")
ReDim lpnt(0 To num * 2 - 1) As Double
pnt = fpnt
lpnt(0) = pnt(0)
lpnt(1) = pnt(1)
Dim st As Integer
For st = 1 To num - 1
pnt = ThisDrawing.Utility.PolarPoint(pnt, (3.14159265 * 2 / num) * (st - 1), leng)
lpnt(st * 2) = pnt(0)
lpnt(st * 2 + 1) = pnt(1)
Next st
Dim pgon As AcadLWPolyline
Set pgon = ThisDrawing.ModelSpace.AddLightWeightPolyline(lpnt)
pgon.Closed = True
ThisDrawing.Regen (True)
'以下语句获取多边形的顶点
Dim gpnt As Variant
gpnt = pgon.Coordinates
Dim pntcnt As Integer
pntcnt = UBound(gpnt)
Dim disptxt As String
disptxt = "多边形共有" & (pntcnt + 1) / 2 & "个顶点" & vbCrLf
Dim i As Integer
For i = 0 To pntcnt - 1 Step 2
disptxt = disptxt & "第" & i / 2 + 1 & "个顶点的坐标为:" & _
gpnt(i) & "," & gpnt(i + 1) & vbCrLf
Next i
disptxt = disptxt & "乐筑天下VBA示例 http://www.mjtd.com"
MsgBox disptxt, , "多边形的坐标显示"
End Sub