Forgot password?

Create an account!


« back

RhinoScript – Doesn't Work


Please log in to write a message.

  • 1. OGAT-ONE (Apr 12, 2011 01.09):

    Hello, new to the scripting process and I recently attended a course which gave an introduction to matrices, and apparently the information went right over my head because this was taught in February and I still cannot Debug the script. Does anyone wanna give it a shot? I is supposed to create a 3d grid of matrices then find the points between and add a surface between these points given their proximity to a curve. I think I missed a step because I can't seem to get it to work. Thank you in advance!!!

    Option Explicit

    Call Main()
    Sub Main()

    dim i, j, k, imax, jmax, kmax
    dim x, y, z, arrPtCoord, matrix
    dim Mdpt1, MdPt4
    dim A, B, C, D, E, F, G, H ' Vertex
    dim AB, BC, CD, DA, EF, FG, GH, HE ' Edge MdPts
    dim AE, BF, CG, DH ' Edge MdPts Between Top and Bottom Face
    dim ABCD, AEBF, BFCG, CGHD, HDAE, EFGH ' Faces
    dim strLine


    imax = 10: jmax =10: kmax = 14

    dim strPath
    strPath = Rhino.GetObject ("PICK PATH", 4)

    redim matrix(imax,jmax,kmax)

    call rhino.EnableRedraw(False)
    for i = 0 to imax
    for j = 0 to jmax
    for k = 0 to kmax

    'Point Coordinates
    X = i+Rnd()*.75
    Y = j+Rnd()*.5
    Z = k+Rnd()*.5
    arrPtCoord = array(X,Y,Z)

    'storage into matrix
    matrix(i,j,k) = arrPtCoord
    'call rhino.AddPoin(i&j&k, matrix(i,j,k))

    'plot point
    'Call Rhino.AddPoint (matrix(i,j,k))

    if i>0 and j>0 and k>0 then

    ' 'Vertex
    A = Matrix (I, J, K )
    B = Matrix (i-1, j, k)
    C = Matrix (i-1, j-1, k)
    D = Matrix (i, j-1, k)
    E = Matrix (i, j, k-1)
    F = Matrix (i-1, j, k-1)
    G = Matrix (i-1, j-1, k-1)
    H = Matrix (i, j-1, k-1)

    ' ' Edge MdPts (Bottom Face)
    AB = PtInBetween (A, B, 0.5)
    BC = PtInBetween (B, C, 0.5)
    CD = PtInBetween (C, D, 0.5)
    DA = PtInBetween (D, A, 0.5)

    ' ' Edge MdPts (Top Face)
    EF = PtInBetween (E, F, 0.5)
    FG = PtInBetween (F, G, 0.5)
    GH = PtInBetween (G, H, 0.5)
    HE = PtInBetween (H, E, 0.5)

    ' ' Edge MdPts (Between Top And Bottom Faces)
    AE = PtInBetween (A, E, 0.5)
    BF = PtInBetween (B, F, 0.5)
    CG = PtInBetween(C, G, 0.5)
    DH = PtInBetween(D, H, 0.5)

    ' Face Centroid
    ABCD = Average4pts (A, B, C, D)
    AE = Average4pts (B, A, E, F)
    BFCG = Average4pts (B, F, C, G)
    CGHD = Average4pts (C, G, H, D)
    HDAE = Average4pts (H, D, A, E)
    EFGH = Average4pts (E, F, G , H)
    dim strCentro
    strCentro = ptInBetween(ABCD, CGHD, 0.5)

    'single path

    ' test compare to nearest crv
    'Project centro onto path
    dim strParam
    strParam = rhino.CurveClosestPoint(strPath, strCentro)

    dim ptOnCrv, dist
    ptOnCrv = rhino.EvaluateCurve(strPath, strParam)

    dist = distToShortestCrv(strCentro, strPath)
    end if
    call rhino.EnableRedraw(true)

    if dist < .5+1*rnd then

    'Plot Modul Srfaces
    call Rhino.AddSrfPt(array(HE,DH,GH))
    call Rhino.AddSrfPt(array(DA,CD,DH))
    call Rhino.AddSrfPt(array(FG,CG,GH))
    call Rhino.AddSrfPt(array(BC,CG,CD))
    call Rhino.AddSrfPt(array(EF,BF,FG))
    End If
    call rhino.EnableRedraw(true)

    End Sub

    function ptInBetween(pt1, pt2, ratio)
    dim pt
    pt = array((pt1(0)+pt2(0))*ratio,_
    ptInBetween = pt
    End Function

    Function Average4Pts(pt1, pt2, pt3, pt4)
    dim pt
    pt = array((pt1(0)+pt2(0)+pt3(0)+pt4(0))/4,_
    Average4pts = pt
    End Function

    Function DistToShortestCrv(Pt, Crvs)
    Dim i, Dist, DistMin
    DistMin = 9999999
    Dim Param, PtOnCrv

    DistToShortestCrv = DistMin

    For i = 0 To UBound(Crvs)

    'Project Centro Onto Path
    Param = Rhino.CurveClosestPoint(Crvs(i), Pt)

    PtOnCrv = Rhino.EvaluateCurve(Path, Param)
    Dist = Rhino.Distance(Pt, PtOnCrv)
    If Dist < DistMin Then
    Dist = Dist
    End If
    End Function


Why are these buttons gray?