Skip to main content
New Participant
February 19, 2023
Answered

Text Source keyframe expression

  • February 19, 2023
  • 1 reply
  • 1162 views

Hi Everyone,
I need help with a simple task.
I have a text layer with 2 keyframes on its "Source text", I want to link those keyframes values to another text's "Source text" values.
So, in my timeline, there are 3 text layers.
The 3rd one is the one that must have those expressions. It has 2 keyframes on the "source text".
So, on the 1st keyframe, it should "become" the 1st layer text, and on the 2nd keyframe, it should become the 2nd layer text.
I attached a picture so you can see it visually.

This topic has been closed for replies.
Correct answer Dan Ebberts

There's probably a more elegant way, but this should work:

if (time < key(2).time)
  thisComp.layer("1st text").text.sourceText
else if (time < key(3).time)
  thisComp.layer("2nd text").text.sourceText
else if (time < key(4).time)
  thisComp.layer("3rd text").text.sourceText
else if (time < key(5).time)
  thisComp.layer("4th text").text.sourceText
else if (time < key(6).time)
  thisComp.layer("5th text").text.sourceText
else
  thisComp.layer("6th text").text.sourceText

This is probably better:

layerNames = ["1st text","2nd text","3rd text","4th text","5th text","6th text"];
n = nearestKey(time).index;
if (time < key(n).time) n--;
if (n > 0) n--;
n = Math.min(n,layerNames.length-1);
thisComp.layer(layerNames[n]).text.sourceText

1 reply

Mylenium
Braniac
February 19, 2023

thisComp.layer("Reference").text.sourceText.valueAtTime(key(1).time)

 

Mylenium

New Participant
February 19, 2023

Thanks for the help, but it didn't work.
It needs 2 expressions, one for the 1st keyframe, and another one for the 2nd keyframe.
I tried to use your script changing for the 2nd one also, but it didn't work.
It works only for one keyframe.
Please, look at my attached picture, it shows what I want to do.

Dan Ebberts
Dan EbbertsCorrect answer
Braniac
February 19, 2023

There's probably a more elegant way, but this should work:

if (time < key(2).time)
  thisComp.layer("1st text").text.sourceText
else if (time < key(3).time)
  thisComp.layer("2nd text").text.sourceText
else if (time < key(4).time)
  thisComp.layer("3rd text").text.sourceText
else if (time < key(5).time)
  thisComp.layer("4th text").text.sourceText
else if (time < key(6).time)
  thisComp.layer("5th text").text.sourceText
else
  thisComp.layer("6th text").text.sourceText

This is probably better:

layerNames = ["1st text","2nd text","3rd text","4th text","5th text","6th text"];
n = nearestKey(time).index;
if (time < key(n).time) n--;
if (n > 0) n--;
n = Math.min(n,layerNames.length-1);
thisComp.layer(layerNames[n]).text.sourceText