Search code examples
arraysanimation3dexpressionmaya

How would I put the values of transformY between frames 1-120 into an array for an expression?


I have pCube1 with transformY animated from frames 1-120. I created an attribute, lowTy and highTy, that I'd like to show the lowest and highest value of transformY's animation.

Here is what I have so far:

Lowest value:

float $array = {THE MISSING PIECE};
$sortedarray = sort($array);
lowTy = $sortedarray[0]

Highest value:

float $array = {THE MISSING PIECE};
int $arraysize = size($array);
$sortedarray = sort($array);
highTy = $sortedarray[$arraysize-1]

The missing piece is being able to put the values of transformY from frames 1-120 into an array. As a note, I don't just need the keyframe values, but the values from all 120 frames keyframed or not. The lowest value of pCube1.transformY is from the tangent handles.

Additional question: How would I return the position of a given value within an array?

Example:

$array = {55, 23, 45, 9, 3, 12, 23)

How do I return the position of 9? (which should be 3) And in the case I try to return the position of 23, how would I choose first (position 1) or second (position 6)?

In the context of my pCube1 scenario, I'd like to quickly locate what frame the highest and lowest values are on.

EDIT: Added a photo for more clarification.

Graph editor screenshot

If I were to modify translateY the lines indicating lowTy and highTy should follow.


Solution

  • YES! I found a way to formulate an expression to do this using loops and getAttr to populate an array with all the values of the attribute in chronological order then used sort to find the lowest value:

    float $arr[];
    int $i;
    float $data = 0;
    int $maxLoop = `playbackOptions -query -aet`;
    for($i=1;$i<$maxLoop;$i++)
        {
            $data = `getAttr -t $i pCube1.translateY`;
            $arr[$i] = $data;
        }
    $arrsort = sort($arr);
    pCube1.test7 = $arrsort[0]