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

rf_setAnimRange.mel

   /*
    Author: Rick Fronek (aka Melvin3D)
    e-mail  : rick@perspectivestudios.com


    description:
            This code looks at an animation od selected node/object
            and sets the animationa and playback to whatever the range
            of the first and the last keyframes are.


    warning:
        that code may destroy any of your project.
        This code is wont be a risc of your projects as is comment lines is longer than the code.
        This is very innocent code.if something bad happens recheck yourself.


    notes:
       I tested that code should work any of maya version 7 and after.
       Did not check for earlier


    special thanks: Mr. Robinson for constantly pushing me ......


    usage :
  */
  //========================================================================
 // This proc needs get a selected object or node and set
    // playbackOptions to whatever the anim range is on that
    // selected object.
    proc float[] rf_getAnimRange()
    {
        float $firstKey;
        float $endKey;
        string $sel[0];
        float $rangeAnim[0];

        //    check if anything is selected.
            $sel = `ls -sl`;
                if(`size($sel)` == 0)    error("No object selected , please select object with anim.");
                    if(`keyframe -q -kc $sel[0]` > 0)
                        {
                             // set the playback to something large
                            // must be set before getting the actual range .
                            // the cmd was skipped otherwise.
                                playbackOptions -ast -100 -aet 10000;
                                playbackOptions -min -100 -max 10000;

                            // Get the first and last key
                                $firstKey = `findKeyframe -ts -w "first" $sel[0]`;
                                $endKey = `findKeyframe -ts -w "last"$sel[0]`;

                            // Assign the two elem to the float array
                            // Either declare the array or assign to individual elements and then return.
                            // float $range[] = {$firstKey , $endKey};
                                $rangeAnim[0] = $firstKey;
                                $rangeAnim[1] = $endKey;
                        }
                        else
                            {
                                error ("No animation found !");
                            }


        // return the range
            return $rangeAnim;
    }

    global proc rf_setAnimRange()
    {
        // store the min and max ranges.
            float $playbackMinMax[] = `rf_getAnimRange`;    // get the return values

        // set those as animation ranges as well.
            playbackOptions -min $playbackMinMax[0] -max $playbackMinMax[1];
            playbackOptions -ast $playbackMinMax[0] -aet $playbackMinMax[1];
            currentTime -e $playbackMinMax[0];
        // as well as playback ranges
        //playbackOptions -min $playbackMinMax[0] -max $playbackMinMax[1];
            print("\n");
            print("Animation playback set to " + "[min] -> " + $playbackMinMax[0] + " [max] -> " + $playbackMinMax[1] + "\n");
    }


    rf_setAnimRange();




     /*
    NOTES :