Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Add expression that only affects first keyframe

  • Add expression that only affects first keyframe

    Posted by Will Bartlett on August 5, 2019 at 2:32 am

    Hi!

    I have a lower thirds title and I’ve setup an expression so that the shape layer automatically changes the width to match whatever length the text layer is:

    dFirst=thisComp.layer("TOP TEXT").sourceRectAtTime(time).width;

    value+[dFirst,0]*thisComp.layer("TOP TEXT").transform.scale[0]/100

    It works great, except I have 2 position keyframes for animating the shape layer from off screen to on screen. If the text layer has too many characters, the first keyfame ends up being pull onto the screen because the entire shape layer is being moved by the expression.

    Is there an expression I can add that will only affect the first keyframe so that it no matter what will keep a value that is off screen for the first frame in the composition?

    And as a bonus I’ve copied and pasted the two keyframes to the end of the comp as well, then time reversed them so that the lower thirds exits the frame in the same way. If the expression would work for the last key frame to be off screen, that would be great!

    Any help would be appreciated!

    Thank you!

    Will Bartlett replied 7 years, 1 month ago 2 Members · 4 Replies
  • 4 Replies
  • Andrei Popa

    August 5, 2019 at 7:12 am

    I suggest you separate position dimensions(right click on position>Separate Dimensions).
    I don’t know how your shape layer looks like(how its anchor is positioned etc) so this is an aproximation of what you will need. You need to calculate the newValue by yourself(this depends on where the anchor point is). I assume your key 2 and key 3 have the same value. If so, this is the expression you put in the x property of position

    newValue = - sourceRectAtTime(time).width;
    time2 = key(3).time;
    if(time <key(3).time){
    linear(transform.xPosition,key(1).value, key(2).value, newValue, key(2).value)
    }else{
    linear(transform.xPosition,key(3).value, key(4).value, newValue, key(3).value)
    }

    Andrei
    My Envato portfolio.

  • Will Bartlett

    August 5, 2019 at 7:16 am

    Thank you for your reply and for the suggestions!

    The shape layer has the anchor set to the left middle side (So it can expand to the right).

    Yes, key 2 and key 3 are the same.

    Will try this out, thanks!

  • Andrei Popa

    August 5, 2019 at 7:20 am

    If the anchor point is not set there by expression, it will move when you make the rectangle bigger. Put this expression in the anchorpoint, in case you don’t already have one:


    var left = sourceRectAtTime(time,false).left;
    [left,value[1]]

    Then, the previous expression should work as it is.

    Andrei
    My Envato portfolio.

  • Will Bartlett

    August 5, 2019 at 4:55 pm

    Ok, Thank you! Appreciate it

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