Answers.Body: <p>To use the keyframed value of a property in an expression, there is a <code>value</code> attribute. And properties also have the <code>key()</code> method to access their keys, as well as the <code>numKeys</code> attribute to find out how many keys the property has. Lastly, there's the global <code>time</code> attribute. </p>
  
  <p>So now we've assembled the list of ingredients, here's how you could put it all together. This expression will use the keyframed value up to the last keyframe, and then hand over the reins to the result of an expression, in this case the value of the slider:</p>
  
  <pre class="lang-js prettyprint-override"><code>// link to your slider, or any calculated value:
  var sliderVal = effect("Slider Control")("Slider"); 
  var lastKey = key(numKeys);
  if (time &lt;= lastKey.time){ // before the last keyframe
    // use the keyframe value before the last keyframe
    value;
  } else {  // after the last keyframe
    // control using the sliders, or any expression
    sliderVal;
  }
  </code></pre>
  
  <p>Of course this will jump from the keyframed value to the expression value instantly at the last keyframe. You can interpolate between the values by using one of the interpolation functions. So to interpolate between the keyframed value and the expression value between the second last keyframe and the last keyframe, you might use:</p>
  
  <pre class="lang-js prettyprint-override"><code>var sliderVal = effect("Slider Control")("Slider"); 
  var k2 = key(numKeys); //last key
  var k1 = key(numKeys - 1); //second last key    
  // linear can take 5 arguments: 
  // time, start time, end time, start val, end val
  // and interpolates between start val and end val
  linear(time, k1.time, k2.time, value, sliderVal)
  </code></pre>
  
  <p>You could also take advantage of the <code>ease()</code>, <code>easeIn()</code> or <code>easeOut()</code> interpolation functions, which you can just substitue for <code>linear()</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-16T08:08:07.883Z
Answers.Text: Wow - that's amazing, thank you so much! I'm not in a position to try this out at the moment but, when I do, I'll absolutely let you know how it goes. Thanks again!
Answers.UserDisplayName: Jamie Bruce
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-14T02:52:27.000Z
Answers.LastActivityDate: 2018-04-14T03:07:35.953Z
Answers.LastEditDate: 2018-04-14T03:07:35.953Z
Answers.UserDisplayName: stib
Body: <p>I'm trying to create a new Essential Graphics template in After Effects.</p>
  
  <p>I have an animation (at its most basic, it's a rectangle that expands from a set, small size to - hopefully! - a user defined size) that can be controlled by moving 4 sliders (it took some fiddling about but I've got a Top Left Null and Bottom Right Null and the 4 sliders control their positions (TL X &amp; Y and BR X &amp; Y), which - in turn - determine the positions for the four corners of the rectangle).</p>
  
  <p>However, having begun setting up the template, I'm slightly worried that this is not going to work. Moving the slider control from within the template window just sets new keyframes (so the animation is all over the place) and, thinking about it now, even if using the template in PP doesn't create new keyframes, how will the EG panel know which keyframe (if any) to affect?</p>
  
  <p>I guess what I'm really wondering is if we can, using an expression, cause the slider controls to affect only the LAST keyframe of an animation (I'm no expression whizz but I can't find anything like that out there following some extensive Googling and I cannot figure out a way to write this myself).</p>
  
  <p>Also, if you think there might be an easier way to do any of this, please let me know!</p>
  
Tags: <after-effects><animation><after-effects-expressions>
Title: After Effects - EG Template: Of 2 keyframes I only want to change the 2nd in EG, help!
UserDisplayName: Jamie Bruce
ThreadText: # After Effects - EG Template: Of 2 keyframes I only want to change the 2nd in EG, help!
  
  (Asked by: username_0 on 2018-04-13)
  
  I'm trying to create a new Essential Graphics template in After Effects.
  
  I have an animation (at its most basic, it's a rectangle that expands from a set, small size to - hopefully! - a user defined size) that can be controlled by moving 4 sliders (it took some fiddling about but I've got a Top Left Null and Bottom Right Null and the 4 sliders control their positions (TL X & Y and BR X & Y), which - in turn - determine the positions for the four corners of the rectangle).
  
  However, having begun setting up the template, I'm slightly worried that this is not going to work. Moving the slider control from within the template window just sets new keyframes (so the animation is all over the place) and, thinking about it now, even if using the template in PP doesn't create new keyframes, how will the EG panel know which keyframe (if any) to affect?
  
  I guess what I'm really wondering is if we can, using an expression, cause the slider controls to affect only the LAST keyframe of an animation (I'm no expression whizz but I can't find anything like that out there following some extensive Googling and I cannot figure out a way to write this myself).
  
  Also, if you think there might be an easier way to do any of this, please let me know!
  
  **Tags:** after-effects, animation, after-effects-expressions
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-14. Score: 1
  
  To use the keyframed value of a property in an expression, there is a `value` attribute. And properties also have the `key()` method to access their keys, as well as the `numKeys` attribute to find out how many keys the property has. Lastly, there's the global `time` attribute.
  
  So now we've assembled the list of ingredients, here's how you could put it all together. This expression will use the keyframed value up to the last keyframe, and then hand over the reins to the result of an expression, in this case the value of the slider:
  
  ```js
  // link to your slider, or any calculated value:
  var sliderVal = effect("Slider Control")("Slider"); 
  var lastKey = key(numKeys);
  if (time <= lastKey.time){ // before the last keyframe
    // use the keyframe value before the last keyframe
    value;
  } else {  // after the last keyframe
    // control using the sliders, or any expression
    sliderVal;
  }
  
  ```
  
  Of course this will jump from the keyframed value to the expression value instantly at the last keyframe. You can interpolate between the values by using one of the interpolation functions. So to interpolate between the keyframed value and the expression value between the second last keyframe and the last keyframe, you might use:
  
  ```js
  var sliderVal = effect("Slider Control")("Slider"); 
  var k2 = key(numKeys); //last key
  var k1 = key(numKeys - 1); //second last key    
  // linear can take 5 arguments: 
  // time, start time, end time, start val, end val
  // and interpolates between start val and end val
  linear(time, k1.time, k2.time, value, sliderVal)
  
  ```
  
  You could also take advantage of the `ease()`, `easeIn()` or `easeOut()` interpolation functions, which you can just substitue for `linear()`.
  
  > **Comments:**
  > **username_0**: Wow - that's amazing, thank you so much! I'm not in a position to try this out at the moment but, when I do, I'll absolutely let you know how it goes. Thanks again!  
  
  ---
  
  