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

VB编程编辑AutoCAD样条曲线

时间:2012-01-18 10:38:39 来源:未知

编辑样条曲线的方法很多,可以通过对其进行拟合进行增加、移动和删除,提高拟合点的权重等操作,可以设置样条曲线的公差,可以提高样条曲线的等级总新定义样条曲线。

一下代码创建一条样条曲线,并改变公差,测试效果。

Private Sub Command1_Click()
    acadapp.ActiveDocument.SetVariable "SPLFRAME", 0
    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) = 1: fitpoints(1) = 1: fitpoints(2) = 0
    fitpoints(3) = 5: fitpoints(4) = 5: fitpoints(5) = 0
    fitpoints(6) = 10: fitpoints(7) = 0: fitpoints(8) = 0
    Set splineobj = acadapp.ActiveDocument.ModelSpace.AddSpline(fitpoints, starttan, endtan)
    ZoomExtents
    splineobj.Update
    Dim currfittolerance As Double
    currfittolerance = splineobj.FitTolerance
    MsgBox "样条曲线拟合公差为" & currfittolerance
    splineobj.FitTolerance = 3
    splineobj.Update
    MsgBox "样条曲线拟合公差改变为" & splineobj.FitTolerance
End Sub

公差越小,各点的拟合情况越好,公差越大,生成的样条曲线月光滑,但各点的拟合情况越差。可以通过设置系统变量SPLFRAME使样条曲线的控制框和控制点显示出来。


相关文章