Forgot password?

Create an account!

Forum

« back

RhinoScript – Array problem

Messages

Please log in to write a message.

  • 3. petertso (May 08, 2008 16.27):

    Hanno,

    Thank you so much. You are the man. Now I can go to sleep!! hehee

    P

  • 2. Hanno (May 05, 2008 17.18):

    Hi there!

    You verify your point array by checking if arrMyPoint(0) is an array. But the problem is that the last element, arrMyPoint(80), is NULL.

    By the way: For array checking my Array Library is quite handy. If you do an

    array_print arrMyPoint

    you can see that the last index is NULL.

    Hanno

  • 1. petertso (May 05, 2008 14.40):

    Can anyone please help out on this script below. It has an error when I try to use the 3D Array to create a curve. I checked and checked and still stuck. Just draw a circle or any curve to start it with.

    Option Explicit
    'Script written by <PetR Tso>
    'Script copyrighted by <MyOwn>
    'Script version 22 April 2008 12:02:24

    Call Main()
    Sub Main()

    Dim CurveID:CurveID=rhino.GetObject("Select baseCurve",4,True,True)
    Dim CurveLength:CurveLength=rhino.CurveLength(CurveID)


    Dim MyY

    'range from-0.8 to 8 for now, step 0.25
    'Number of point=16/0.25+1

    Dim SinePerCir:SinePerCir=6
    Dim Amplitude:Amplitude=CurveLength/50
    Dim PtPerCir:PtPerCir=80

    Dim x:x=-SinePerCir*rhino.Pi
    Dim y:y=SinePerCir*rhino.Pi
    Dim dblstep:dblstep=(y-x)/PtPerCir

    Dim arrMyPoint(80)

    Dim SineInputX,PtCount

    PtCount=-1

    'Dim MyPolylinePt:ReDim MyPolylinePt(80)

    For SineInputX=x To y Step dblstep

    PtCount=PtCount+1

    'ReDim Preserve arrMyPoint(PtCount)

    MyY=DrawSineWave(SineInputX,Amplitude)
    arrMyPoint(PtCount)=VecDir(CurveID,PtPerCir, PtCount, MyY)



    Next

    If IsArray(arrMyPoint) Then Call rhino.Print("points seems ok")
    If IsArray(arrMyPoint(0)) Then Call rhino.Print("point array also seems ok")

    'Dim MyCurve:MyCurve=rhino.AddCurve(arrMyPoint,3)

    Call rhino.Print(arrMyPoint(0)(0)&","&arrMyPoint(0)(1)&","&arrMyPoint(0)(2))
    Call rhino.Print(UBound(arrMyPoint))



    'MyPolyLine=rhino.Addpoint(arrMyPoint)


    End Sub

    Function VecDir(ByVal inPutCurve, ByVal NumOnCurve, ByVal inPuti, ByVal Yparam)
    VecDir=Null

    Dim PtOnCurve
    Dim i:i=inPuti
    If i>NumOnCurve-1 Then Exit Function

    PtOnCurve=rhino.DivideCurve(inPutCurve,NumOnCurve)

    Dim vecPt,vecA, vecB
    Dim vecZworld
    Dim arrowA,arrowB

    Dim x1,y1,z1
    Dim x2,y2,z2

    x1=PtOnCurve(i)(0)
    y1=PtOnCurve(i)(1)
    z1=PtOnCurve(i)(2)

    If i=NumOnCurve-1 Then
    x2=PtOnCurve(0)(0)
    y2=PtOnCurve(0)(1)
    z2=PtOnCurve(0)(2)
    Else
    x2=PtOnCurve(i+1)(0)
    y2=PtOnCurve(i+1)(1)
    z2=PtOnCurve(i+1)(2)
    End If



    vecPt=rhino.VectorCreate(Array(x1,y1,z1),Array(x2,y2,z2))

    vecZworld=rhino.VectorCreate(Array(x1,y1,z1),Array(x1,y1,1))
    vecPt=rhino.VectorCrossProduct(vecPt,vecZworld)

    'The following line add Z variation to sine curve
    vecPt=rhino.PointAdd(vecPt,Array(0,0,Yparam/8))

    vecPt=rhino.VectorUnitize(vecPt)

    Dim Point
    Dim mX,mY,mZ
    Dim arrMyPoint

    If Yparam>=0 Then
    vecPt=rhino.VectorScale(vecPt,Yparam)
    Point=rhino.PointAdd(PtonCurve(i),vecPt)

    mX=Point(0)
    mY=Point(1)
    mZ=Point(2)
    arrMyPoint=Array(mX,mY,mZ)

    Else

    vecPt=rhino.VectorScale(vecPt,Yparam)
    Point=rhino.PointAdd(PtonCurve(i),vecPt)

    mX=Point(0)
    mY=Point(1)
    mZ=Point(2)
    arrMyPoint=Array(mX,mY,mZ)

    End If

    'arrowA=AddVector(vecPt,Array(x1,y1,z1))



    VecDir=arrMyPoint

    End Function

    Function DrawSineWave(ByVal dblStep, ByVal Amp)

    Dim x, y

    x = dblStep
    y = Amp*Sin(x)

    DrawSineWave=y

    End Function

    Function AddVector(ByVal vecDir, ByVal ptBase)
    On Error Resume Next
    AddVector = Null

    If IsNull(ptBase) Or Not IsArray(ptBase) Then
    ptBase = Array(0,0,0)
    End If

    Dim ptTip
    ptTip = Rhino.PointAdd(ptBase, vecDir)
    If Not (Err.Number = 0) Then Exit Function

    AddVector = Rhino.AddLine(ptBase, ptTip)
    If Not (Err.Number = 0) Then Exit Function
    If IsNull(AddVector) Then Exit Function

    Call Rhino.CurveArrows(AddVector, 0)
    End Function

Recommend

Why are these buttons gray?