Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Modify linear expression to use fourth and fifth keyframes of a property

  • Modify linear expression to use fourth and fifth keyframes of a property

    Posted by David Cabestany on May 4, 2022 at 5:57 pm

    I use this expression structure a lot:

    r=transform.yPosition;
    k1=transform.yPosition.key(1).value;

    k2=transform.yPosition.key(2).value;

    ease(r,k1,k2,0,22)


    Today I’m trying to to the same but instead of using keyframes 1 and 2 y need to use the 4th and 5th, so I wrote this instead:


    f=thisComp.layer(“50MM”).cameraOption.zoom;

    k1=thisComp.layer(“50MM”).cameraOption.zoom.key(4).value;

    k2=thisComp.layer(“50MM”).cameraOption.zoom.key(5).value;

    linear(f,k1,k2,100,0);


    But when I play the animation the value before the third keyframe is 100, and I need it to be 0 up until the moment it hits the 4th keyframe.

    When the 4th keyframe is reached the animation happens as expected.

    Thanks in advance for your help.

    David Cabestany replied 2 years, 4 months ago 2 Members · 9 Replies
  • 9 Replies
  • Dan Ebberts

    May 4, 2022 at 7:01 pm

    Try this:

    f=thisComp.layer("50MM").cameraOption.zoom;

    k1=f.key(4).value;

    k2=f.key(5).value;

    time < f.key(4).time ? 0 : linear(f,k1,k2,100,0);

  • David Cabestany

    May 5, 2022 at 3:44 pm

    Works great, thanks a lot Dan.

  • David Cabestany

    May 6, 2022 at 1:19 am

    Hey Dan, sorry to be a pest but I think I jumped the gun too fast, the expression is not working and instead is returning the error f.key is not a function.

    I tried making f different properties, such as position or rotation but nothing worked.

    I was looking at a different expression when I said this one worked. My bad.

  • Dan Ebberts

    May 6, 2022 at 4:37 am

    Hmm… It works for me. The only way I can make it fail with that message is to do this:

    f=thisComp.layer("50MM").cameraOption;

    instaed of this:

    f=thisComp.layer("50MM").cameraOption.zoom;

    Maybe you could post a screen shot.

  • David Cabestany

    May 10, 2022 at 3:50 pm

    I’m trying to use it on a different comp with different properties, writing this:

    f=thisComp.layer(“cam ctrl”).transform.position[2];

    k1=f.key(2).value[2];

    k2=f.key(3).value[2];

    time < f.key(2).time ? 0 : linear(f,k1,k2,0,58);

  • Dan Ebberts

    May 10, 2022 at 4:17 pm

    I’d suggest trying it this way:

    f=thisComp.layer("cam ctrl").transform.position;

    k1=f.key(2).value[2];

    k2=f.key(3).value[2];

    time < f.key(2).time ? 0 : linear(f[2],k1,k2,0,58);

  • David Cabestany

    May 10, 2022 at 10:04 pm

    that did the trick. thanks a lot.

    is the last part before the linear expression a new format for using an if/else statement?

  • Dan Ebberts

    May 10, 2022 at 10:20 pm

    Not new (it’s the JavaScript conditional operator), but I like it because you can use it on a single line with minimal punctuation.

  • David Cabestany

    May 11, 2022 at 5:15 pm

    Looks like I have some catch-up reading to do then.

    Thanks!

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