Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Create / Modify key frames positions values with expression

  • Create / Modify key frames positions values with expression

  • Clement Dubois

    November 3, 2021 at 10:06 am

    Hi !

    I am wondering if there is a way to modify the values of position keyframe with my expression.

    I have a layer with a drop menu effect and a position expression :

    dropMenu = effect("Dropdown Menu Control")("Menu");

    if (dropMenu ==1) {
    mPosition= 300;
    }else if (dropMenu== 2) {
    mPosition= 500
    };

    [value[0], mPosition]

    To be precise, I want to animate the position value, I wonder if there is a way to apply or modify the value of a keyframe if I change the dropmenu value ?

  • Dan Ebberts

    November 3, 2021 at 1:49 pm

    You can’t actually modify keyframes with expressions, but you might be able to simulate the result, depending on what you need to do. You can certainly use the timing of the keyframes to drive your expression animation, but it can get tricky if you also need to preserve the easing of your keyframes. You can probably do it if you just need to proportion the keyframe animation based on the value of your dropdown menu, but it depends on the details of how you have things set up.

  • Tomas Bumbulevičius

    November 3, 2021 at 2:46 pm

    Hey Clement, the question here is whats behind as well as ahead of your selected keyframe to be modified

    As Dan mentioned – directly you won’t be able to alter it. However, if you give us a bigger picture of task, I am sure workaround can be found.

  • Clement Dubois

    November 5, 2021 at 2:51 pm

    Hi !

    I sent you a picture of the work I try to achieve.

    As you can see on the picture, by changing the drop menu value, I want to automatically change the value of the 2nd position keyframe but keep the animation and the value of the 1st position value.

    And the expression I wrote don’t work 😕

  • Andrei Popa

    November 6, 2021 at 8:33 am

    Hi Clement. I think you need one of the following expressions, based on whether the second value of y position is greater or smaller than the first. The linear() function needs the 2nd parameter to be smaller than the 3rd.

    So if the position of your second keyframe is lower than the first, use this

    dropMenu = effect("Dropdown Menu Control")("Menu");
    myListe = [195.7, 258.2, -320.7];
    myPlace = myListe[dropMenu - 1];
    key1 = key(1).value[1];
    key2 = key(2).value[1];
    yVal = linear(value[1], key1, key2, key1, key2 + myPlace);
    [value[0], yVal];

    Otherwise, use this

    dropMenu = effect("Dropdown Menu Control")("Menu");
    myListe = [195.7, 258.2, -320.7];
    myPlace = myListe[dropMenu - 1];
    key1 = key(1).value[1];
    key2 = key(2).value[1];
    yVal = linear(value[1], key2, key1, key2 + myPlace, key1);
    [value[0], yVal];

    You need to modify these a little to fit your project.

  • Dan Ebberts

    November 6, 2021 at 6:52 pm

    There are some situations where you might need a different approach. For example, if the y position of the 1st and 2nd keyframes are the same (and maybe the y value goes above and/or below the keyframe value in between). In that case you might want to proportion the y offset, based on how far along you are between the two keyframes, like this:

    dropMenu = effect("Dropdown Menu Control")("Menu");

    myListe = [195.7, 258.2, 320.7, 445.7, 508.2, 570.7, 633.2, 695.7, 758.2, 820.7, 883.2];

    myPlace = myListe[dropMenu - 1];

    t1 = key(1).time;

    t2 = key(2).time;

    yOffset = linear(time,t1,t2,0,myPlace)

    value + [0,yOffset]

  • Clement Dubois

    November 22, 2021 at 12:45 pm

    Hi, thank you, Andrei and Dan for your replies.

    I tried what you sent, and the second expression of Andrei work fine !

Viewing 1 - 7 of 7 posts

Log in to reply.

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