- 积分
- 934
- 明经币
- 个
- 注册时间
- 2004-11-11
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2004-11-18 20:44:00
|
显示全部楼层
On Error GoTo ErrHandle Dim pnt Dim picked As Boolean Dim px() As Double Dim py() As Double Dim i, k As Integer Dim pcenter() As Double Dim insertdistance() As Double Me.Hide Do While 1 pnt = ThisDrawing.Utility.GetPoint ThisDrawing.SendCommand "-boundary" & vbCr & "a" & vbCr & "b" & vbCr & "e" & vbCr & vbCr & pnt(0) & "," & pnt(1) & vbCr & vbCr Set pr = ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1) Dim retCoord As Variant retCoord = pr.Coordinates k = (UBound(retCoord) + 1) / 2
ReDim px(UBound(retCoord)) As Double ReDim py(UBound(retCoord)) As Double For i = 0 To UBound(retCoord) Step 2 px(i / 2) = retCoord(i) py(i / 2) = retCoord(i + 1) Next i ReDim insertdistance(k) As Double For i = 0 To k - 2 '用点选的方法获得点坐标,然后判断图形形状,计算形状面积,累加所有点选图形面积计算式。结果如图所示: A*B + C*D + E*F insertdistance(i) = Sqr((px(i) - px(i + 1)) * (px(i) - px(i + 1)) + (py(i) - py(i + 1)) * (py(i) - py(i + 1)))
ReDim pcenter(k) As Double ReDim insertdistance(k) As Double For i = 0 To k - 2 '此处要解决最后一个点和起始点的距离测定问题 pcenter(i) = (px(i) + px(i + 1)) / 2 pcenter(i + 1) = (py(i) + py(i + 1)) / 2 + 0.2 insertdistance(i) = Sqr((px(i) - px(i + 1)) * (px(i) - px(i + 1)) + (py(i) - py(i + 1)) * (py(i) - py(i + 1))) ThisDrawing.ModelSpace.AddText insertdistance(i), pcenter, 0.65%%%%%%%%%%当此语句存在时,程序就会出错,
Next i If k = 4 Then '这是四边形的情况 ssss = insertdistance(0) & "*" & insertdistance(1) Else '还有一种情况是六边形 ssss = insertdistance(0) & "*" & insertdistance(1) & "+" & insertdistance(3) & "*" & insertdistance(4) '此处得到了是面积的式子,而且要求每次点击六边形或者四边行要把前面得到的式子再追加上来。…………………………………………………… End If MsgBox ssss '这里其实应该显示的结果如图所示 picked = True Loop ErrHandle: Me.Show
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|