请各位大虾帮忙看一下这个DVB程序错在哪?
请各位大虾帮忙看一下这个DVB程序错在哪?<BR> 这段绘制抛物线函数曲线程序运行时总是提示:"运行时错误: 方法 'AddLightWeightPolyline' 作用于对象 'IAcadModelSpace' 时失败.Sub Test()
Dim p1(0 To 2) As Double<BR>Dim p2 As Variant<BR>Dim pntobj As Variant
Dim lobj As AcadLWPolyline<BR>Dim vers(0 To 20000) As Double
Dim k As Double<BR>Dim g As Double<BR>Dim b As Double
Dim x1 As Double<BR>Dim y1 As Double<BR>Dim x As Double<BR>Dim y As Double<BR>Dim i As Double<BR>Dim a As Double
Dim l As Double<BR>Dim m As Double<BR>Dim n As Double<BR>Dim O As Double<BR>Dim P As Double<BR>Dim Q As Double
'确定抛物线函数曲线的参数K的值
g = 32.7718 / 1000<BR>b = 68.5036<BR>k = g / (2 * b)
'确定抛物线函数曲线的第一点的坐标<BR>l = 100<BR>m = 100<BR>n = 0<BR>p1(0) = l<BR>p1(1) = m<BR>p1(2) = n
'提取当前鼠标的动态坐标
p2 = ThisDrawing.Utility.GetPoint(, "p2:")
'p2 = GetPoint<BR>O = p2(0)<BR>P = p2(1)<BR>Q = p2(2)
'计算抛物线曲线函数参数X1、Y1的值<BR>x1 = (P - m + k * l ^ 2 - k * O ^ 2) / (2 * k * (l - O))<BR>y1 = m - k * (l - x1) ^ 2
'确定抛物线函数曲线的第一点<BR>vers(0) = l<BR>vers(1) = m
i = p1(0)<BR>a = 2
'利用循环确定函数曲线上的端点之间的若干坐标值<BR>If i < p2(0) Then<BR> While i <= p2(0)<BR> x = i<BR> y = k * ((x - x1) * 10) ^ 2 + y1<BR> i = i + 0.5<BR> vers(a) = x<BR> vers(a + 1) = y<BR> a = a + 2<BR> Wend<BR>Else<BR> While i > p2(0)<BR> x = i<BR> y = k * ((x - x1) * 10) ^ 2 + y1<BR> i = i - 0.5<BR> vers(a) = x<BR> vers(a + 1) = y<BR> a = a + 2<BR> Wend<BR>End If
'确定抛物线函数曲线的最后一点<BR>vers(a) = p2(0)<BR>vers(a + 1) = p2(1)
'利用多义线绘制抛物线+函数曲线<BR>Set lobj = ThisDrawing.ModelSpace.AddLightWeightPolyline(vers)
On Error GoTo ErrTrap<BR> Set ehObj = New Hook<BR> ehObj.Enabled = True<BR> ThisDrawing.Utility.GetPoint<BR> ehObj.Enabled = False<BR> Set ehObj = Nothing<BR> Exit Sub<BR> <BR>ErrTrap:<BR> ehObj.Enabled = False<BR> Set ehObj = Nothing<BR>End Sub<BR> 你的Set ehObj = New Hook
这个Hook是什么? 知道了你把Dim vers(0 To 20000) As Double改为Dim vers(0 To 20001) As Double就行了,呵呵。 多谢指点!现在程序已可以运行成功了。但是,不知为什磨非要写成: Dim vers(0 To 20001) As Double的形式? LightWeightPolyline是二维多段线,vers应该是二维点数组
页:
[1]