[expression] value to the keyframe

Hi

Please help me to solve my problem. I want to change the value of specific keyframe . How can I do that?



I want to change the value of yellow keyframe with an expression.

I think it’s not possible to access and control specific keyframe with expressions.
The only real workaround is to use “markers as triggers” workflow, but it gets pretty messy really quick, especially if you have multiple keyframes and you want to use this in more than one layer.

If you choose to go that route one advice - Once buyer set’s up everything he/she should convert all those expressions to keyframes, save it and restart AE, because AE does not clean up memory after each keyframe and if you have multiple layers with “markers as triggers” you could get “not enough memory” message.

I have used this workflow in few of mine templates where idea was that client just slides markers and by doing so he/she adjusts scene duration. But it is not worth it, takes too much time and you have to create script that (after user sets up all markers) converts all those expressions to keyframes.

It would be really great if there were something like
x=effect(“Point Control”)(“Point”);

keyframe.05 = x;

or maybe something like this
x=effect(“x offsett”)(“Slider”);

keyframe.05 = value+[x,0].

But as far as I know there is no such option. Felt will know for sure and I think that he is gonna comment here also.

It is possible, but a bit complicated.

  • The trick is to ascertain which keyframe indeces are the next and last ones relative to the current time.
  • Then you check if the current time is in the zone between the 3 keyframes that the expression will change.
  • there are two zones.. animating into the new keyframe and animating back out. If the key to change is 3 as in the example, these correspond to the space between key2 and key3, and the space between key3 and key4.
  • Then you convert the original movement into a completeness ratio, a value between 0 and 1. In the example shown, this will actually be two values because it's a 2D position.
  • Then you multiply the completeness ratio by the new vector to be covered and add it to the value of the last keyframe value...being careful to note that in the second zone the last keyframe value will be the new value.

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;
}

PS… @ivezicm

I wouldn’t worry about converting expressions to keyframes. Ae handles all but the most heavy duty scripts fine, in my experience. (and by heavy duty, I’m talking about a long expression - 100 lines or more - with a lot of looping or a long preroll - very rare).

Many of my projects have many, many long expressions tucked away in them to make life easier for the buyer, and I haven’t had an “out of memory” complaint yet.

Thanks Felt and ivezicm. It really means a lot for me. I spent 30 min on this expression to learn your solution felt and how did you wrote it !! Have you ever try making a epression blog for someone like me? Your knowledge helps a lot to ae’s people. A blog like “jjgifford” helps everyone.

Regards

moviePlankton said

Thanks Felt and ivezicm. It really means a lot for me. I spent 30 min on this expression to learn your solution felt and how did you wrote it !! Have you ever try making a epression blog for someone like me? Your knowledge helps a lot to ae’s people. A blog like “jjgifford” helps everyone.

Regards

I’ve got a few expressions tuts here… https://vimeo.com/channels/222304

Felt could write a book on AE and i think it would be bestseller.
If you wish to learn more on expressions take a look at this http://www.amazon.com/After-Effects-Expressions-Marcus-Geduld/dp/024080936X it’s really great book.