下面是我写的一个绘制长圆(两端是半圆、中间是矩形)的VBA程序,可根据用户提供的中心坐标、长轴长度和短轴长度、长轴与X轴正方向的夹角绘制方向任意的长圆。
-
- Public Sub CreateLongCircle()
-
- '获取长圆中心坐标
- Dim center As Variant
- center = ThisDrawing.Utility.GetPoint(, "请在屏幕上拾取一点作为长圆的中心或输入中心坐标:")
-
- '获取长轴与X轴正方向夹角
- Dim angle As Double
- angle = pi / 180 * ThisDrawing.Utility.GetReal("请输入长轴与X轴正方向的夹角:")
-
- '获取长轴长度
- Dim longAxis As Double
- longAxis = ThisDrawing.Utility.GetReal("请输入长轴长度:")
-
- '获取短轴长度
- Dim shortAxis As Double
- shortAxis = ThisDrawing.Utility.GetReal("请输入短轴长度:")
-
- Dim halfL As Double
- halfL = (longAxis - shortAxis) / 2
- Dim halfS As Double
- halfS = shortAxis / 2
-
- '计算各顶点坐标
- Dim vertices(1 To 8) As Double
- vertices(1) = center(0) + halfL: vertices(2) = center(1) - halfS
- vertices(3) = center(0) + halfL: vertices(4) = center(1) + halfS
- vertices(5) = center(0) - halfL: vertices(6) = center(1) + halfS
- vertices(7) = center(0) - halfL: vertices(8) = center(1) - halfS
-
- Dim plineObj As AcadLWPolyline
- Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(vertices)
-
- plineObj.Closed = True
- plineObj.SetBulge 0, 1
- plineObj.SetBulge 2, 1
-
- '旋转长圆
- plineObj.Rotate center, angle
- plineObj.Update
-
- End Sub
但是我运行后发现每次绘制出来的长圆都是长轴平行于X轴,Rotate函数好像没起作用,请问问题出在哪里?非常感谢!
|