调用 Autocad 的 AddLine 函数时出错 API

Error while calling AddLine function of Autocad API

我正在为 Autocad 2013 在 UFT 中进行 API 编程,如下所示:

Public Function Test() 
    Dim oApp, oDoc , sptr(2) , eptr(2) , objLine 
    Set oApp = GetObject(,"Autocad.Application")
     Set oDoc = oApp.ActiveDocument 
    sptr(0) = 1 : sptr(1) = 1 : sptr(2) = 0 
    eptr(0) = 5 : eptr(1) = 5 :eptr(2) = 0 
    Set objLine = oDoc.ModelSpace.AddLine(sptr,eptr) 
    oApp.Visible = True 
  End Function 

   Call Test()

我在 Set objLine 收到以下错误:

Invalid procedure call or argument

由于是VBScript,这样传递起点和终点的方式正确吗?

AddLine() 函数需要一个 Double 值数组。 VBScript 只能创建 Variant 个值的数组。幸运的是,AutoCAD 包含一个名为 CreateTypedArray() 的函数作为其 Utility class 的一部分,它允许您创建 typed 数组,然后您可以将其传递给 AutoCAD函数。

Dim s, e
oDoc.Utility.CreateTypedArray s, vbDouble, 1, 1, 0   ' Make 's' a Double array
oDoc.Utility.CreateTypedArray e, vbDouble, 5, 5, 0   ' Make 'e' a Double array
Set objLine = oDoc.ModelSpace.AddLine(s, e)          ' Pass our new arrays