- Public Sub 画圆标注直径()
- Dim AcAdApp As Object
- Dim ThisDrawing As Object
-
- On Error Resume Next
-
- Set AcAdApp = GetObject(, "AutoCAD.Application")
- If Err Then
- MsgBox "请打开AutoCAD,再执行程序!", vbInformation
- Exit Sub
- End If
-
- Set ThisDrawing = AcAdApp.ActiveDocument
-
-
- Dim circleobj As Object
- Dim centerpoint(0 To 2) As Double
- Dim radius As Double
- Dim returnPnt As Variant
-
-
- returnPnt = ThisDrawing.Utility.GetPoint(, "请指定圆心点: ")
- centerpoint(0) = returnPnt(0): centerpoint(1) = returnPnt(1): centerpoint(2) = returnPnt(2)
- radius = ThisDrawing.Utility.GetDistance(returnPnt, "请输入半径R=: ")
-
- Set circleobj = ThisDrawing.ModelSpace.AddCircle(centerpoint, radius)
- Dim dimobj As Object
- Dim chordpoint(0 To 2) As Double
- Dim farchordpoint(0 To 2) As Double
- Dim leaderlength As Double
- Dim Angle As Double
-
- Angle = Atn(1#) '标注时与图上X轴正向的夹角,设为沿45°方向标注
- chordpoint(0) = centerpoint(0) + radius * Cos(Angle)
- chordpoint(1) = centerpoint(1) + radius * Sin(Angle)
- chordpoint(2) = centerpoint(2)
- farchordpoint(0) = centerpoint(0) - radius * Cos(Angle)
- farchordpoint(1) = centerpoint(1) - radius * Sin(Angle)
- farchordpoint(2) = centerpoint(2)
- leaderlength = 1#
- Set dimobj = ThisDrawing.ModelSpace.AddDimDiametric(chordpoint, farchordpoint, leaderlength)
- End Sub
|