Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions controlling 4 keyframes with sourcerectattime

  • controlling 4 keyframes with sourcerectattime

    Posted by Adam Greenberg on October 11, 2022 at 9:21 pm

    Hi, I am trying to solve a problem. I have used a manual workaround for this issue for a long time, but Id like to solve it properly once and for all.

    I have included a reduced version of the project. Basically I have 6 key frames, the 1<sup>st</sup> and 6<sup>th</sup> are off screen and should always be fixed positions. The 2<sup>nd</sup> key frame is the end of the opening animation which I would like to be controlled by the sourcerectatime property of my text, which I have done successfully in other scenerios. There is a blue guide showing where the text needs to end.

    This position is also for the 3rd keyframe.

    Now for the 4th keyframe, I have another position to consider, there is a second text that comes in now, and this new position should be controlled by that 2nd text’s sourrectattime property for keyframes 4 and 5. I have included a project that have manual keyframes, but is there a way to change these values to be driven by the text while respecting the animation curve of the position ?

    Thanks for any help.

    Filip Vandueren replied 2 years, 3 months ago 2 Members · 9 Replies
  • 9 Replies
  • Filip Vandueren

    October 12, 2022 at 6:30 am

    Does it need to be set up with a precomp 5 levels deep ?

    That really complicates the setup and makes the expression a bit harder.

  • Adam Greenberg

    October 12, 2022 at 12:49 pm

    No Filip, it doesnt, thats just how one happens to be right now

  • Adam Greenberg

    October 13, 2022 at 1:48 pm

    Here is much better version. Sorry for the complicated first version. I have a 2nd composition in this project just in case the first one is still too difficult to fully automate

  • Filip Vandueren

    October 14, 2022 at 7:26 am

    Hi Adam, this expression on the position keyframes seems to do it:

    marginRight = 1720;
    precomp1=thisComp.layer("right");
    txt1=precomp1.source.layer("title");
    sr1=txt1.sourceRectAtTime();
    precomp2 =thisComp.layer("titre droit");
    txt2 = precomp2.source.layer("day time");
    sr2=txt2.sourceRectAtTime();
    offset1 = parent.fromComp(
    precomp1.toComp(
    txt1.toComp(
    [sr1.left+sr1.width, sr1.top+sr1.height]
    ),2
    ),2
    ) - parent.fromComp([marginRight,0]);
    offset1[1]=0;
    offset2 = parent.fromComp(
    precomp2.toComp(
    txt2.toComp(
    [sr2.left+sr2.width, sr2.top+sr2.height]
    ),8
    ),8
    ) - parent.fromComp([marginRight,0]);
    offset2[1]=0;
    p1=key(1).value;
    p2=key(2).value;
    p3=key(4).value;
    p4=key(6).value;
    if (time<key(2).time) {
    linear(value[0],p1[0],p2[0],p2-offset1,p1);
    } else if (time<key(4).time) {
    linear(value[0],p2[0],p3[0],p2-offset1,p3-offset2);
    } else {
    linear(value[0],p3[0],p4[0],p3-offset2,p4);
    }

    I tested it with a number of different titles and it seems to work ok, but let me know if you run into an edge case where it doesn’t perform as expected.

  • Adam Greenberg

    October 14, 2022 at 2:12 pm

    Filip, that’s insane, it works perfectly.

    Now I need to study this code to understand it fully. When I apply it in other cases with somewhat different parameters, I’ll need to know how to edit it.

    Thank you so much. I think I’ll repost this project with better layer names in my next reply. For sure it has to be helpful to others out there. maybe it could serve as a rig.

    👍🤝💪

  • Adam Greenberg

    October 28, 2022 at 1:46 pm

    Hi Filip, I have one more question regarding the rig you solved.

    I need a small graphic to be revealed by the incoming black box ( between key frame 1 and 2 ) , but after its initial animation, it needs to follow the graphic as if its part of it ( as if it was parented )

    All positions of this rig are controlled by the text length, ( except for key frame 1 and 6 ).

    I need this layer to act as if it was parented to the graphic, but ignore keyframe 1, which means it will be revealed by the graphic when we arrive at keyframe 2, and then follow it from then on.

    And if you remember, keyframe 2 and 3 and 4 and 5 are all dynamically controlled by the text length, and because of this I cannot figure out the syntax. Its infuriating. It seems like a simple expression when I thought of the logic.

    Here is small quicktime of what it should look like and the project reposted with all uneccessary layers hidden.

    I appreciate any help anyone can provide.

  • Filip Vandueren

    October 28, 2022 at 2:24 pm

    Hi Adam,

    – set your time indicator somewhere between key 2 and 3.

    – position the shape where you want it to be.

    – parent it to “22 animation with keyframes”

    – give the position of the shape this expression:

    t=parent.position.key(2).time;
    myAbsolutePosition = parent.toComp(value,t);
    if (time<t) {
    parent.fromComp(myAbsolutePosition);
    } else {
    value;
    }
  • Adam Greenberg

    October 28, 2022 at 2:59 pm

    this is amazing and yet so simple, I think this opens up so much flexibility in so many other situations. I can’t thank you enough Filip. Have a great day !!!

  • Filip Vandueren

    October 28, 2022 at 3:58 pm

    In the previous code I simply used “2” instead of key(2).time, but in this setup the result is the same. Happy it all works for you.

    Good luck with the rest.

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