Sub Test()
Dim Pnt As Variant
Dim CirCenter As Variant
Dim Radius1 As Double, Radius2 As Double
Dim Circle1 As AcadCircle, Circle2 As AcadCircle
Dim TempLine As AcadLine
Dim DistPtCen As Double
Dim PolylinePt As Variant
Dim Polyline As AcadPolyline
Dim Line1 As AcadLine, Line2 As AcadLine
’Enter the center and radius of the circle
CirCenter = ThisDrawing.Utility.GetPoint(, "圆心位置:")
Radius1 = ThisDrawing.Utility.GetDistance(CirCenter, "圆的半径:")
’Draw the circle
Set Circle1 = ThisDrawing.ModelSpace.AddCircle(CirCenter, Radius1)
’Specify the point from where the tangent line start
Pnt = ThisDrawing.Utility.GetPoint(, "切线起点:")
’Draw the point
ThisDrawing.ModelSpace.AddPoint (Pnt)
’Calculate the length of the tangent line
Set TempLine = ThisDrawing.ModelSpace.AddLine(CirCenter, Pnt)
DistPtCen = TempLine.Length
TempLine.Delete
Radius2 = Sqr(DistPtCen ^ 2 - Radius1 ^ 2)
’Draw a auxiliary circle with radius equals the length of tangent line
Set Circle2 = ThisDrawing.ModelSpace.AddCircle(Pnt, Radius2)
PolylinePt = Circle1.IntersectWith(Circle2, acExtendNone)
Set Polyline = ThisDrawing.ModelSpace.AddPolyline(PolylinePt)
’Add tangent lines
Set Line1 = ThisDrawing.ModelSpace.AddLine(Pnt, Polyline.Coordinate(0))
Set Line2 = ThisDrawing.ModelSpace.AddLine(Pnt, Polyline.Coordinate(1))
’Delete the auxiliary circle and polyline
Circle2.Delete
Polyline.Delete
Sub Test()
Dim Pnt As Variant
Dim CirCenter As Variant
Dim Radius1 As Double, Radius2 As Double
Dim Circle1 As AcadCircle, Circle2 As AcadCircle
Dim TempLine As AcadLine
Dim DistPtCen As Double
Dim PolylinePt As Variant
Dim Polyline As AcadPolyline
Dim Line1 As AcadLine, Line2 As AcadLine
’Enter the center and radius of the circle
CirCenter = ThisDrawing.Utility.GetPoint(, "圆心位置:")
Radius1 = ThisDrawing.Utility.GetDistance(CirCenter, "圆的半径:")
’Draw the circle
Set Circle1 = ThisDrawing.ModelSpace.AddCircle(CirCenter, Radius1)
’Specify the point from where the tangent line start
Pnt = ThisDrawing.Utility.GetPoint(, "切线起点:")
’Draw the point
ThisDrawing.ModelSpace.AddPoint (Pnt)
’Calculate the length of the tangent line
Set TempLine = ThisDrawing.ModelSpace.AddLine(CirCenter, Pnt)
DistPtCen = TempLine.Length
TempLine.Delete
Radius2 = Sqr(DistPtCen ^ 2 - Radius1 ^ 2)
’Draw a auxiliary circle with radius equals the length of tangent line
Set Circle2 = ThisDrawing.ModelSpace.AddCircle(Pnt, Radius2)
PolylinePt = Circle1.IntersectWith(Circle2, acExtendNone)
Set Polyline = ThisDrawing.ModelSpace.AddPolyline(PolylinePt)
’Add tangent lines
Set Line1 = ThisDrawing.ModelSpace.AddLine(Pnt, Polyline.Coordinate(0))
Set Line2 = ThisDrawing.ModelSpace.AddLine(Pnt, Polyline.Coordinate(1))
’Delete the auxiliary circle and polyline
Circle2.Delete
Polyline.Delete
全部回复(3 )
只看楼主 我来说两句Dim Pnt As Variant
Dim CirCenter As Variant
Dim Radius1 As Double, Radius2 As Double
Dim Circle1 As AcadCircle, Circle2 As AcadCircle
Dim TempLine As AcadLine
Dim DistPtCen As Double
Dim PolylinePt As Variant
Dim Polyline As AcadPolyline
Dim Line1 As AcadLine, Line2 As AcadLine
’Enter the center and radius of the circle
CirCenter = ThisDrawing.Utility.GetPoint(, "圆心位置:")
Radius1 = ThisDrawing.Utility.GetDistance(CirCenter, "圆的半径:")
’Draw the circle
Set Circle1 = ThisDrawing.ModelSpace.AddCircle(CirCenter, Radius1)
’Specify the point from where the tangent line start
Pnt = ThisDrawing.Utility.GetPoint(, "切线起点:")
’Draw the point
ThisDrawing.ModelSpace.AddPoint (Pnt)
’Calculate the length of the tangent line
Set TempLine = ThisDrawing.ModelSpace.AddLine(CirCenter, Pnt)
DistPtCen = TempLine.Length
TempLine.Delete
Radius2 = Sqr(DistPtCen ^ 2 - Radius1 ^ 2)
’Draw a auxiliary circle with radius equals the length of tangent line
Set Circle2 = ThisDrawing.ModelSpace.AddCircle(Pnt, Radius2)
PolylinePt = Circle1.IntersectWith(Circle2, acExtendNone)
Set Polyline = ThisDrawing.ModelSpace.AddPolyline(PolylinePt)
’Add tangent lines
Set Line1 = ThisDrawing.ModelSpace.AddLine(Pnt, Polyline.Coordinate(0))
Set Line2 = ThisDrawing.ModelSpace.AddLine(Pnt, Polyline.Coordinate(1))
’Delete the auxiliary circle and polyline
Circle2.Delete
Polyline.Delete
End Sub
回复 举报
Dim Pnt As Variant
Dim CirCenter As Variant
Dim Radius1 As Double, Radius2 As Double
Dim Circle1 As AcadCircle, Circle2 As AcadCircle
Dim TempLine As AcadLine
Dim DistPtCen As Double
Dim PolylinePt As Variant
Dim Polyline As AcadPolyline
Dim Line1 As AcadLine, Line2 As AcadLine
’Enter the center and radius of the circle
CirCenter = ThisDrawing.Utility.GetPoint(, "圆心位置:")
Radius1 = ThisDrawing.Utility.GetDistance(CirCenter, "圆的半径:")
’Draw the circle
Set Circle1 = ThisDrawing.ModelSpace.AddCircle(CirCenter, Radius1)
’Specify the point from where the tangent line start
Pnt = ThisDrawing.Utility.GetPoint(, "切线起点:")
’Draw the point
ThisDrawing.ModelSpace.AddPoint (Pnt)
’Calculate the length of the tangent line
Set TempLine = ThisDrawing.ModelSpace.AddLine(CirCenter, Pnt)
DistPtCen = TempLine.Length
TempLine.Delete
Radius2 = Sqr(DistPtCen ^ 2 - Radius1 ^ 2)
’Draw a auxiliary circle with radius equals the length of tangent line
Set Circle2 = ThisDrawing.ModelSpace.AddCircle(Pnt, Radius2)
PolylinePt = Circle1.IntersectWith(Circle2, acExtendNone)
Set Polyline = ThisDrawing.ModelSpace.AddPolyline(PolylinePt)
’Add tangent lines
Set Line1 = ThisDrawing.ModelSpace.AddLine(Pnt, Polyline.Coordinate(0))
Set Line2 = ThisDrawing.ModelSpace.AddLine(Pnt, Polyline.Coordinate(1))
’Delete the auxiliary circle and polyline
Circle2.Delete
Polyline.Delete
End Sub
虽然写得不好,不过也可以做切线了,
才学vba不到一个月,还请大家指教。
回复 举报