Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to link a keyframe to a slider control

  • How to link a keyframe to a slider control

    Posted by Ramon Peppelenbos on January 27, 2015 at 5:05 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

    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

    Suraj Perera replied 4 years, 8 months ago 5 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    January 27, 2015 at 7:23 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

  • Ramon Peppelenbos

    January 27, 2015 at 7:49 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

  • Amit Patel

    February 2, 2015 at 5:45 pm

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

  • Igor Repin

    June 7, 2017 at 12:35 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

  • Suraj Perera

    September 2, 2021 at 12:33 pm

    Amazing and very helpful for me.. Thank you so much !

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy