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

rf_utilFunction.mel

/*========================================================================
   AUTHOR : Rick Fronek (TD)
   UPDATED : 07-28-09
   DESCRITPTION :
                                        this function looks at the selection and returns >>>
                                        Return first element
                                        Return last element
                                        Return everything but last element
                                        Return everything but first element

    REQUIRES :  An aruments , selection - string array and decision int for the switch()
========================================================================

*/
        proc rf_utilFunction(string $array[], int $code)
        {
            // get selection from the arg.
            string $selection[0]; clear $selection;
            string $tmpList[0] ; clear $tmpList;
            int $loop = 0;

            $selection = $array;
                if(size($selection) < 2)
                    error ("Select atleast 2 objects..!");

            int $x = 0;
            switch($code)
            {
                case 0:
                    // get the first elem in the list
                            string $firstElem = $selection[0];
                            select -r $firstElem;
                            print ($firstElem + "\n");
                    break;

                case 1:
                        // get the last elem in the list
                            string $lastElem = $selection[size($selection) - 1];
                            select -r $lastElem;
                            print ($lastElem + "\n");
                    break;

                case 2:
                        // get everything but the first elem
                            for($x = 1; $x < size($selection);$x++)
                                {
                                    // store the items into the list
                                    $tmpList[`size($tmpList)`] = $selection[$x];
                                    print ($selection[$x] + "\n");
                                }
                                select -r $tmpList;
                    break;

                case 3:
                        // get everything but the last elem
                            for($x; $x < size($selection) - 1;$x++)
                                {
                                    $tmpList[`size($tmpList)`] = $selection[$x];
                                    print ($selection[$x] + "\n");
                                }
                                select -r $tmpList;
                    break;
            }

        }

        global proc rf_listFunction(int $code)
        {
            string $selection[] = `ls -sl`;
            rf_utilFunction($selection , $code);
            print(".................................................\n");
        }

    // Arguments can be 0,1,2,3
    rf_listFunction(2);