Forgot password?

Create an account!

Forum

« back

RhinoScript – recurse

Messages

Please log in to write a message.

  • 3. pulgarata (Oct 08, 2012 19.57):

    Option Explicit
    Call Main()
    Sub Main()
            Dim strCurve,arrCentroid,arrPoints,Temp,ArrCurv,Crv,Crvx
            ReDim Temp(0)
            Dim n:n = 0
            Dim Lp:Lp = 1
            Dim intGen:intGen = 3 'esta es la cantidad de bucles que necesitas
            strCurve = Rhino.GetObject("select a closed Curve", 4)
           
            Do
                    If isarray(ArrCurv) Then
                            For Each Crv In ArrCurv
                                    Temp = Triangulate(Crv)
                                    For Each Crvx In Temp
                                            ReDim Preserve Temp2(n)
                                            Temp2(n) = Crvx
                                            n = n + 1              
                                    Next
                            Next
                            ArrCurv = Temp2
                    Else
                            ArrCurv = Triangulate(strCurve)
                    End If 
                    Lp = Lp + 1
            Loop Until Lp > intGen
    End Sub

    Function Triangulate(strCurve)
            Dim i,arrCentroid,arrPoints
            arrCentroid = Rhino.CurveAreaCentroid(strCurve)
            arrPoints = Rhino.CurvePoints(strCurve)
            rhino.AddPoint(arrCentroid(0))
            ReDim ArrCrv(UBound(arrPoints) -1)
            For i = 0 To UBound(arrPoints) - 1
                    ArrCrv(i) = Rhino.AddPolyline(Array(arrCentroid(0), arrPoints(i), arrPoints(i + 1), arrCentroid(0)))
            Next
            Triangulate = ArrCrv
    End Function

    Hola, Prueba con esto.

    Saludos,

    Seba.

  • 2. Hanno (Oct 08, 2012 09.03):

    Hi,

    pay attention to where and when you declare your variables and where you are using them (for example, you are calling Triangulate without any parameters, and then within that function you are using variables that are only declared in main.
    Maybe add an "option explicit" at the beginning of your script, as this will help you get your variables in order.

    Hope that helps

    Hanno

  • 1. mauro (Oct 07, 2012 21.51):

    Hi, I am try to recurse this function in order to subdivide all the triangles in smaller ones,
    for some reason it douse not loop all the way through the triangles.
    somebody knows how?
    Thanks

    Call Main()
    Sub Main()
    Dim strCurve,intGen,arrCentroid,arrPoints
    strCurve = Rhino.GetObject("select a closed Curve",4)
    arrCentroid = Rhino.CurveAreaCentroid(strCurve)
    rhino.AddPoint(arrCentroid(0))

    arrPoints = Rhino.CurvePoints(strCurve)
    intGen = 5

    Call Triangulate

    End Sub

    Sub Triangulate(arrPoints,intGen)
    If (intGen<1) Then
    Call Triangle(arrCenter,arrpoints)
    Else
    Call Triangulate(Array(arrCenter(0),arrPoints(i),arrPoints(i+1),arrCenter(0)),intGen-1)
    End If
    End Sub

    Sub Triangle(arrCenter,arrpoints)

    Dim i,strTria,arrCenter

    For i = 0 To UBound(arrPoints)-1
    strTria = Rhino.AddPolyline(Array(arrCenter(0),arrPoints(i),arrPoints(i+1),arrCenter(0)))
    Next
    arrCenter = Rhino.CurveAreaCentroid(strTria)
    End Sub

Recommend

Why are these buttons gray?