请各位大虾帮忙看一下这个DVB程序错在哪? 这段绘制抛物线函数曲线程序运行时总是提示:"运行时错误: 方法 'AddLightWeightPolyline' 作用于对象 'IAcadModelSpace' 时失败.
Sub Test()
Dim p1(0 To 2) As Double Dim p2 As Variant Dim pntobj As Variant
Dim lobj As AcadLWPolyline Dim vers(0 To 20000) As Double
Dim k As Double Dim g As Double Dim b As Double
Dim x1 As Double Dim y1 As Double Dim x As Double Dim y As Double Dim i As Double Dim a As Double
Dim l As Double Dim m As Double Dim n As Double Dim O As Double Dim P As Double Dim Q As Double
'确定抛物线函数曲线的参数K的值
g = 32.7718 / 1000 b = 68.5036 k = g / (2 * b)
'确定抛物线函数曲线的第一点的坐标 l = 100 m = 100 n = 0 p1(0) = l p1(1) = m p1(2) = n
'提取当前鼠标的动态坐标
p2 = ThisDrawing.Utility.GetPoint(, "p2:")
'p2 = GetPoint O = p2(0) P = p2(1) Q = p2(2)
'计算抛物线曲线函数参数X1、Y1的值 x1 = (P - m + k * l ^ 2 - k * O ^ 2) / (2 * k * (l - O)) y1 = m - k * (l - x1) ^ 2
'确定抛物线函数曲线的第一点 vers(0) = l vers(1) = m
i = p1(0) a = 2
'利用循环确定函数曲线上的端点之间的若干坐标值 If i < p2(0) Then While i <= p2(0) x = i y = k * ((x - x1) * 10) ^ 2 + y1 i = i + 0.5 vers(a) = x vers(a + 1) = y a = a + 2 Wend Else While i > p2(0) x = i y = k * ((x - x1) * 10) ^ 2 + y1 i = i - 0.5 vers(a) = x vers(a + 1) = y a = a + 2 Wend End If
'确定抛物线函数曲线的最后一点 vers(a) = p2(0) vers(a + 1) = p2(1)
'利用多义线绘制抛物线+函数曲线 Set lobj = ThisDrawing.ModelSpace.AddLightWeightPolyline(vers)
On Error GoTo ErrTrap Set ehObj = New Hook ehObj.Enabled = True ThisDrawing.Utility.GetPoint ehObj.Enabled = False Set ehObj = Nothing Exit Sub
ErrTrap: ehObj.Enabled = False Set ehObj = Nothing End Sub