本帖最后由 qwh923820 于 2018-7-18 14:34 编辑
假如 Dim x(1 To 9) As Object 改成 Dim x(1 To 9) As AcadObject 就会出错,在x(j).Delete这一步VBA直接就崩溃了。这是什么原因?
- Sub 主程序()
- Dim i&, j&, d As Double
- Dim pt1(2) As Double, pt2(2) As Double, pt3(2) As Double
- Dim x(1 To 9) As Object
- pt1(0) = 0: pt1(1) = 0
- 'p8,p9竖向对称线
- pt2(0) = pt1(0) + 200
- pt2(1) = pt1(1) - 100
- pt3(0) = pt2(0)
- pt3(1) = pt1(1) + 2000
- d = 1.2 '板厚度
-
- Call 调用(pt1, x, i, d)
- For j = 1 To i
- x(j).Mirror pt2, pt3
- x(j).Delete
- Next j
- End Sub
- Sub 调用(ByVal pt1, ByRef x, ByRef i, ByVal d)
- Dim y, g(1 To 16) As Double
- g(1) = pt1(0) + 50: g(2) = pt1(1) - 15
- g(3) = g(1): g(4) = pt1(1)
- g(5) = g(3) - 50: g(6) = g(4)
- g(7) = g(5): g(8) = g(4) - 116
- g(9) = g(5) + 30: g(10) = g(8)
- g(11) = g(9): g(12) = g(10) - 36
- g(13) = g(11) + 30: g(14) = g(12)
- g(15) = g(13): g(16) = g(14) + 15
- i = i + 1
- Set x(i) = ThisDrawing.ModelSpace.AddLightWeightPolyline(g)
- y = x(i).Offset(-d)
- i = i + 1
- Set x(i) = y(0)
- Erase y
- End Sub
|