ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How to link a keyframe to a slider control

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ramon peppelenbos
How to link a keyframe to a slider control
on Jan 27, 2015 at 5:05:02 am

Hey all,

I want to do something fairly simple:

Got 2 keyframes on the opacity of a layer

The first keyframe has a value of 0
The second keyframe has a value of 0

Now I want to be able to control the second keyframe with a slider control. So when the slider value is 50, the keyframe value is 50 (so the animation will be from 0 to 50). is there a keyframe index that I can use to link it up with a slider control? and in a way where I can simply change the slider and everything will update without issues?

I've found expression that does the trick, but they seem way too complex for my situation and I have no idea what's going on here:


keyNumToChange = 3; //change this - the key num to change (numbering starts at 1)
newVal = [1500, 460]; //change this - the new position.
//-------
nearKey = thisLayer.position.nearestKey(time).index;
lastKey = (thisLayer.position.key(nearKey).time>time) ? ((nearKey>1) ? nearKey-1 : nearKey) : nearKey;
nextKey = (lastKey<thisLayer.position.numKeys) ? lastKey+1 : lastKey;
nextVal =thisLayer.position.key(nextKey).value;
lastVal = thisLayer.position.key(lastKey).value;

if(nextKey == keyNumToChange) {
xRatio = ((nextVal[0]-lastVal[0]) != 0) ? ((thisLayer.position.value[0]-lastVal[0]) / (nextVal[0] -lastVal[0])) : 1;
xVal = lastVal[0]+(newVal[0]-lastVal[0])*xRatio;
yRatio = ((nextVal[1]-lastVal[1]) != 0) ? ((thisLayer.position.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) ? ((thisLayer.position.value[0]-lastVal[0]) / (lastVal[0] -nextVal[0])) : 1;
xVal = newVal[0]+(newVal[0]-nextVal[0])*xRatio;
yRatio = ((nextVal[1]-lastVal[1]) != 0) ? ((thisLayer.position.value[1]-lastVal[1]) / (lastVal[1] -nextVal[1])) : 1;
yVal = newVal[1]+(newVal[1]-nextVal[1])*xRatio;
[xVal, yVal];
} else {
value;
}



I would love to understand how this expression works, but primairly I'd like to know to write something a little more simplified (if possible) and how it exactly works.

Thanks in advance

Regards,

Ramon Peppelenbos


Return to posts index

Dan Ebberts
Re: How to link a keyframe to a slider control
on Jan 27, 2015 at 7:23:25 am

I think an opacity expression like this would do the trick:


if (numKeys > 1){
t1 = key(1).time;
t2 = key(2).time;
v1 = 0;
v2 = effect("Slider Control")("Slider");
linear(time,t1,t2,v1,v2);
}else
value



Dan



Return to posts index

Ramon peppelenbos
Re: How to link a keyframe to a slider control
on Jan 27, 2015 at 7:49:32 am
Last Edited By Ramon peppelenbos on Jan 27, 2015 at 7:57:36 am

Thanks a lot, does the trick. Could you perhaps explain how this exactly works?

Not familiar with numKeys, key().time and how linear() works in combo with that. Or perhaps you got some resource I can read to fully understand what's happening

I've also noticed there is no real way to easy eaze, has that something to do with linear?

Regards,

Ramon


Return to posts index


Amit Patel
Re: How to link a keyframe to a slider control
on Feb 2, 2015 at 5:45:42 pm

It would be great if you can explain same expression for Position, rotation and scale. You are Great !


Return to posts index

Igor Repin
Re: How to link a keyframe to a slider control
on Jun 7, 2017 at 12:35:57 pm

Hi there! It's really helpful! Is it possible to add to this script a inertial bounce? I tried to combine two scenarios, but this was unsuccessful.

if (numKeys > 1){
t1 = key(1).time;
t2 = key(2).time;
v1 = 0;
v2 = effect("Slider Control")("Slider");
linear(time,t1,t2,v1,v2);
}else
value


Return to posts index

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