Creating curve from vba

I have an excel spreadsheet which I am trying to create wireframe using VBA. Lines and arcs I have successfully done, as well as reading the ordinates of a curve into the spreadsheet. This spreadsheet does a lot of analysis for us so this is the preferred method, rather than having the automation as a rhino script. Below is the vba code I have written to create the curve, but when it does the addcurve call I get a run-time error 10 about an array being fixed or temporarily locked. Any ideas anybody?

Sub RhinoCreateCurve()
    Dim Rh As Object
    Dim RhScr As Object
    Dim SelObject As Variant
    Dim NumPoints As Integer
    Dim CurPoint() As Variant
    Dim XYZ() As Variant
    Set Rh = CreateObject("Rhino5.Interface")
    Set RhScr = Rh.GetScriptObject()
    NumPoints = Sheets("Sheet1").Cells(1, 5).Value
    ReDim CurPoint(NumPoints - 1)
    ReDim CurPoint(NumPoints)
    ReDim XYZ(2)
    For i = 1 To NumPoints
        XYZ(0) = Sheets("Sheet1").Cells(i, 6).Value
        XYZ(1) = Sheets("Sheet1").Cells(i, 7).Value
        XYZ(2) = Sheets("Sheet1").Cells(i, 8).Value
        CurPoint(i - 1) = XYZ
    Next i
    RhScr.AddCurve CurPoint
End Sub

Hi David,

Arrays in VB/VBA/VBS are different than most other languages in that an array’s dimension ranges from 0 to the highest index value, not the number of elements.

For example

Redim arrPoint(10)

declares an array that holds 11 values (0 through 10), not 10 values.

I’ve taken your script and modified it a bit (see attached). See if this works any better.

– Dale (14.1 KB)

thanks for that. Works perfectly.