ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Change keyframe value using expression

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Doni Donovan
Change keyframe value using expression
on Mar 12, 2019 at 2:26:56 am
Last Edited By Doni Donovan on Mar 12, 2019 at 2:28:31 am

I found this script a couple month ago..
Is there a chance to tweak it so i can change the value for all/both keyframes?

keyNumToChange = 2; //change this - the key num to change(numbering starts at 1)
newVal = [value[0],100]; //change this - the new size.
target = transform.position;
//-------
nearKey = target.nearestKey(time).index;
lastKey =(target.key(nearKey).time>time) ?((nearKey>1) ? nearKey-1 : nearKey) : nearKey;
nextKey =(lastKey<target.numKeys) ? lastKey+1 : lastKey;
nextVal =target.key(nextKey).value;
lastVal = target.key(lastKey).value;

if(nextKey == keyNumToChange) {
xRatio =((nextVal[0]-lastVal[0]) != 0) ?((target.value[0]-lastVal[0]) /(nextVal[0] -lastVal[0])) : 1;
xVal = lastVal[0]+(newVal[0]-lastVal[0])*xRatio;
yRatio =((nextVal[1]-lastVal[1]) != 0) ?((target.value[1]-lastVal[1]) /(nextVal[1] -lastVal[1])) : 1;
yVal = lastVal[1]+(newVal[1]-lastVal[1])*xRatio;
[xVal, yVal];
} else if(lastKey == keyNumToChange) {
xRatio =((nextVal[0]-lastVal[0]) != 0) ?((target.value[0]-lastVal[0]) /(lastVal[0] -nextVal[0])) : 1;
xVal = newVal[0]+(newVal[0]-nextVal[0])*xRatio;
yRatio =((nextVal[1]-lastVal[1]) != 0) ?((target.value[1]-lastVal[1]) /(lastVal[1] -nextVal[1])) : 1;
yVal = newVal[1]+(newVal[1]-nextVal[1])*xRatio;
[xVal, yVal];
} else {
value;
}


Thanks for reply :)


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]