-
- Public Function DrawRectang(RecHalfWidth As Double) As Object
- Dim Pt1 As Variant
- Dim Pt2 As Variant
- Dim RectRotation As Double
- Dim objPolyline As Object
- Dim RectangPoint(0 To 11) As Double
-
- ' 获得第一点Pt1
- Pt1 = ThisDrawing.Utility.GetPoint(, "指定起始点")
- ' 获得第二点Pt2
- Pt2 = ThisDrawing.Utility.GetPoint(Pt1, "指定结束点")
- ' 得到两点构成直线的的角度值
- RectRotation = Atn((Pt2(1) - Pt1(1)) / (Pt2(0) - Pt1(0)))
-
- ' 根据Pt1、Pt2两点计算矩形各顶点坐标
- RectangPoint(0) = Pt1(0) - RecHalfWidth * Sin(RectRotation)
- RectangPoint(1) = Pt1(1) + RecHalfWidth * Cos(RectRotation)
-
- RectangPoint(3) = Pt1(0) + RecHalfWidth * Sin(RectRotation)
- RectangPoint(4) = Pt1(1) - RecHalfWidth * Cos(RectRotation)
-
- RectangPoint(6) = Pt2(0) + RecHalfWidth * Sin(RectRotation)
- RectangPoint(7) = Pt2(1) - RecHalfWidth * Cos(RectRotation)
-
- RectangPoint(9) = Pt2(0) - RecHalfWidth * Sin(RectRotation)
- RectangPoint(10) = Pt2(1) + RecHalfWidth * Cos(RectRotation)
-
- Set objPolyline = ThisDrawing.ModelSpace.AddPolyline(RectangPoint)
- objPolyline.Closed = True
-
- Set DrawRectang = objPolyline
- End Function
|