您的位置:网站首页 > CAD新闻

VB编程在AutoCAD绘图空间创建曲线

时间:2012-01-19 10:09:12 来源:未知

VB可以在AutoCAD绘图空间中创建圆、弧、椭圆和样条曲线等多种曲线对象。

利用AddCircle方法可以创建圆形对象,该方法需要给出圆形的三维坐标和圆的半径。如下代码创建一个圆心为(20,30,0),半径为5的圆。

Private Sub Command1_Click()
    Dim circleobj As AcadCircle
    Dim centerpoint(0 To 2) As Double
    Dim radius As Double
    centerpoint(0) = 20#: centerpoint(1) = 30#: centerpoint(2) = 0#
    radius = 5#
    Set circleobj = acadapp.ActiveDocument.ModelSpace.AddCircle(centerpoint, radius)
    ZoomAll
End Sub

利用AddArc方法可以创建弧,该方法需给出圆弧圆心三维坐标、圆半径、起始角度和终止角度。利用AddEllipse方法可以创建椭圆,该方法需给出椭圆中心三维坐标、长轴一个断点三维坐标和短长轴之比。

利用AddSpline方法可以创建样条曲线,该方法徐需给出所有需要拟合的三维定点坐标数组,数组个数必须是3的倍数,定义起点和终点切线方向的两个向量。下面的代码创建一条经过(2,1,0)、(3,5,0)、(10,3,0)曲线起点和终点的切线向量均为(0.5,0.5,1)的样条曲线。

Private Sub Command1_Click()
    Dim splineobj As AcadSpline
    Dim noofpoints As Integer
    Dim starttan(0 To 2) As Double
    Dim endtan(0 To 2) As Double
    Dim fitpoints(0 To 8) As Double
    noofpoints = 3
    starttan(0) = 0.5: starttan(1) = 0.5: starttan(2) = 0
    endtan(0) = 0.5: endtan(1) = 0.5: endtan(2) = 0
    fitpoints(0) = 2: fitpoints(1) = 1: fitpoints(2) = 0
    fitpoints(3) = 3: fitpoints(4) = 5: fitpoints(5) = 0
    fitpoints(6) = 10: fitpoints(7) = 3: fitpoints(8) = 0
    Set splineobj = acadapp.ActiveDocument.ModelSpace.AddSpline(fitpoints, starttan, endtan)
    ZoomAll
End Sub