Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Text Source keyframe expression

Community Beginner ,
Feb 19, 2023 Feb 19, 2023

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.

TOPICS
Expressions , Scripting
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Feb 19, 2023 Feb 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
Translate
Community Expert , Feb 19, 2023 Feb 19, 2023

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
Translate
LEGEND ,
Feb 19, 2023 Feb 19, 2023

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

 

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 19, 2023 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2023 Feb 19, 2023

You could do it like this:

if (time < key(2).time)
  thisComp.layer("1st text").text.sourceText
else
  thisComp.layer("2nd text").text.sourceText
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 19, 2023 Feb 19, 2023

Thanks a lot, Dan. you really helped me.
But I actually need this for ~6 texts and keyframes.
I tried this method for 3 texts and keyframes, and it didn't work.
could you help me again?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2023 Feb 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2023 Feb 19, 2023
LATEST

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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines