3D animation,rigging,coding, math ,fun stuff welcome !

selectEvenOddObject.mel

/*
SCRIPT : domino_selectOddEven.mel

AUTHOR : Rick Fronek (TD)
UPDATED : 07.23.09
DESCRIPTION : Takes a list of selection and selects either odd or even
              nodes. I used this for domino project where I had 300
              dominos in the scene (Bulls, Bears) needed to apply tex.
              to either odd or even dominos.

REQUIRES : Argument > 0 = even 1 = odd and common sense.

*/


// Need a function that will take selection and filters it and spits out either
// odd or even selected objects.Great for huge amount of objects. I used this
// to quickly select dominos , I had a scene with 500 dominos.
    proc string[] rf_selectOddEven(int $evenOrOdd)
     {
        // list t return
        string $returnObjList[0];
        clear $returnObjList;
        // store current selection
        string $selection[] = {};
        clear $selection;
        // get only transform types from current selection
        $selection = `ls -sl -tr`;
        if (`size($selection)` == 0)
            error "You need to select a list of objects!";
        // deselect everything ...selection is stored in the list above.
        select -d;

        // an int to loop with
        int $num = 0;
        // loop and print the names.
        for($node in $selection)
            {
             if ($evenOrOdd == 0)
                {
                 // get ODD number selection,use the remainder.
                 if(($num % 2) == 0)
                    {
                     print ($num + "\n");
                     select -tgl $node;
                     $returnObjList[size($returnObjList)] = $node;
                    }
                }
             if ($evenOrOdd == 1)
                {
                 // only grab EVEN number selection
                 if (($num % 2) == 1)
                    {
                     print ($num + "\n");
                     select -tgl $node;
                     $returnObjList[size($returnObjList)] = $node;
                    }
                }

                // count + 1 everytime you loop
                $num += 1;
            }

        // return the list
        return $returnObjList;

     } *********************************END***********************************


    // test the function
    global proc rf_printResult()
    {
        // print the results , pass what you want odd/even
        //Argument > 0 = even 1 = odd
        string $list[] = rf_selectOddEven(1);
        for ($i in $list)
            print ($i + "\n");
    }    // end function

    rf_printResult();