Forgot password?

Create an account!

Forum

« back

RhinoScript – delete dublicates in array

Messages

Please log in to write a message.

  • 6. atac (Nov 30, 2010 18.22):

    ok.. thanks again to johannes and Hanno. Thats exactly what I am looking for...

  • 5. Johannes (Nov 28, 2010 23.44):

    you can try the function with my script. the CullDuplicatePoints function works with 3d-points. that means x,y,z - coordinates.

    Option Explicit

    Call Main()
    Sub Main()

           
            Dim arrTest     : ReDim arrTest(4)
           
            arrTest(0) = array(0,10,15)
            arrTest(1) = array(0,8,15)
            arrTest(2) = array(0,10,15)     
            arrTest(3) = array(0,10,15)
            arrTest(4) = array(0,1,15)
           
           
            arrTest = Rhino.CullDuplicatePoints(arrTest)
           
            Call DupArray(arrTest)
           
           
    End Sub


    Function DupArray(arrTest)

            Dim i, j
           
            Call Rhino.PrintEx("+++ Calculation result: +++")
           
            For i = 0 To Ubound(arrTest) -1
                    For j = 0 To (Ubound(arrTest)) - (i+1)
                            If arrTest(i)(0) = arrTest(i+j+1)(0) And _
                                    arrTest(i)(1) = arrTest(i+j+1)(1) And _
                                    arrTest(i)(2) = arrTest(i+j+1)(2) Then
                                   
                                    Call Rhino.PrintEx("arrTest( " & i & ") - equals - arrTest(" & i+j+1 & ")")
                                   
                            End If
                    Next
            Next

    End Function

    then my script may be a useful tool ;)

  • 4. atac (Nov 28, 2010 22.48):

    thanks for your answers!

    my points only exists in the array. i got them from start / endpoint from curves or meshes. the cullDublicatePoints method only works when I create the points in Rhino? Is that right?

    Best regards
    atac

  • 3. Hanno (Nov 28, 2010 22.30):

    Hi,

    the nested loop that Johannes shows below is a good (or the) way to compare every item in an array with all other items and do whatever you want based on the results.
    However, for the specific need of removing duplicate points from an array, RhinoScript comes with the nice method CullDuplicatePoints which does exactly that.

    Regards

    Hanno

  • 2. Johannes (Nov 28, 2010 10.47):

    Hi,

    you can write a function to test your array.
    maybe you can use some of the following code:

    Call Main()
    Sub Main()

            Dim arrTest     : ReDim arrTest(4)
           
            arrTest(0) = array(0,10,15)
            arrTest(1) = array(0,8,15)
            arrTest(2) = array(0,10,15)     
            arrTest(3) = array(0,10,15)
            arrTest(4) = array(0,1,15)
           
            Call DupArray(arrTest)
                   
    End Sub

    Function DupArray(arrTest)

            Dim i, j
           
            Call Rhino.PrintEx("+++ Calculation result: +++")
           
            For i = 0 To Ubound(arrTest) -1
                    For j = 0 To (Ubound(arrTest)) - (i+1)
                            If arrTest(i)(0) = arrTest(i+j+1)(0) And _
                                    arrTest(i)(1) = arrTest(i+j+1)(1) And _
                                    arrTest(i)(2) = arrTest(i+j+1)(2) Then
                                   
                                    Call Rhino.PrintEx("arrTest( " & i & ") - equals - arrTest(" & i+j+1 & ")")
                                   
                            End If
                    Next
            Next

    End Function

    you get the positions of double entries.

  • 1. atac (Nov 27, 2010 20.15):

    Hello!

    I hope I can find some help here in the forum. I have got an array of 3d Points. Some of the point coordinates are equal.

    Is there a simple way to delete the dublicates in the array? In the sample below "myarray(2)" should be deleted.

    myarray(0)(0) = 15  'x value of 3d point
    myarray(0)(1) = 10  'y value of 3d point
    myarray(0)(2) = 5   'z value of 3d point


    myarray(1)(0) = 3
    myarray(1)(1) = 19
    myarray(1)(2) = 8


    myarray(2)(0) = 15
    myarray(2)(1) = 10
    myarray(2)(2) = 5

    Thanks for any help.
    atac

Recommend

Why are these buttons gray?