Forgot password?

Create an account!

Forum

« back

RhinoScript – Array required with Addcurve

Messages

Please log in to write a message.

  • 7. xavido (Aug 11, 2010 09.25):

    Now works!

    Thank you very much!!

  • 6. Johannes (Aug 10, 2010 13.15):

    try something like that:

    Dim arrPoints
    ReDim arrPoints(0)

    instead of

    Dim arrPoints(0)

  • 5. xavido (Aug 10, 2010 13.10):

    Thanks Johannes, but it doesn't work...

    Appears an error message saying 'This array is fixed or temporarily locked'

    It also appears using the code you attached...

    Thank you!

  • 4. Johannes (Aug 10, 2010 12.39):

    no problem...

    in your version you declared the array with name(size)... so its fixed.

    there is a function to resize an array dynamicly.. its called Redim Preserve name(newsize)

    ' declare variables
    Dim arrPoints(0)
    Dim intUbound

    ' loop
    Do

    ' Ubound function to get the last index of an array
    intUbound = Ubound(arrPoints)

    ' add a point at the last position
    arrPoints(intUbound) = array(x,y,z)

    ' resize the array + 1
    ReDim Preserve arrPoints(intUbound + 1)

    loop

    ' resize the array - 1
    ReDim Preserve arrPoints(intUbound - 1)

    Call Rhino.AddCurve(arrPoints)
  • 3. xavido (Aug 10, 2010 12.30):

    Thanks!!!

    Now, what do I need to do if I want it to be dynamic?

    The code I exposed was just an idea, but in my real code I don't know how many points will I have until the end of the loop, so I can't declare an array wich I don't know which its dimension will be, can I??

    Thank you Johannes!

  • 2. Johannes (Aug 10, 2010 12.15):

    arrPointCurve has 6 positions -> Dim arrPointcurve(5)

    you just checked arrPointCuvre(0) and arrPointCurve(1)...
    take a look on the other 4 because the Rhino.AddCurve functions wants to use the whole array and needs at every position one 3dPoint.

    if you just want to use 2 points change the code to -> Dim arrPointcurve(1)

  • 1. xavido (Aug 10, 2010 11.39):

    I got a problem with Addcurve, here's my code:

    Dim arrPointcurve(5)
     
     z=1
     Do
          arrCurve = Rhino.CurveMeshIntersection(Line_aux, Mesh, 0)
          If IsNull(arrCurve) Then Exit Do
          Pm_x=arrCurve(0)(0)
          Pm_y=arrCurve(0)(1)
          Pm_z=arrCurve(0)(2)
          arrPointcurve(z)=Array(Pm_x,Pm_y,Pm_z)
          z=z+1
          'If z=5 Then Exit Do
      Loop
      arrPointcurve(0)=Talo(0)
      Rhino.print Pt2Str(arrPointCurve(0))
      Rhino.print Pt2Str(arrPointCurve(1))
     
      Rhino.AddCurve arrPointcurve

    There are more lines of code inside the loop but I omited them. My problem is that an error message appears saying 'An array is required' on the line of Addcurve.

    As you can see, I have a correct array of 3D points, and I just checked it by using the print function.

    What am I doing wrong?? Thanks in advance!

Recommend

Why are these buttons gray?