Skip to main content
Participant
September 27, 2021
Answered

Changing text (array) layer contents based on frame number range

  • September 27, 2021
  • 1 reply
  • 458 views

I found the below expression for displaying text in an array for every frame by frame. However, I was looking to tweak this expression to display the texts/strings in an array based on its corresponding frameNos range arrary as a condition.

 

mArr=[1,2,3,56,676,567,899];

mFrame=timeToFrames(time);

mArr[mFrame]

(this expression was provided in the thread - https://community.adobe.com/t5/after-effects-discussions/changing-text-layer-contents-frame-by-frame/m-p/9543218)

 

Example: Text to display = Text 1, Text 2....so on but based on frame numbers i.e. Text 1 to appear between frame range 10 to 50 and Text 2 to display between frame range 20 to 40 in a new line.

 

Array break up would as a CSV like below,

Text_1, 10, 50

Text_2, 20, 40

 

Any help is appreciated on how this can be achieved.

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

If you put your data in a layer marker comment like this

 

Text_1, 10, 50
Text_2, 20, 40

 

Then an expression like this should work:

c = marker.key(1).comment;
splitC = c.split("\r");
txt = "";
f = timeToFrames(time);
for (i = 0; i < splitC.length; i++){
  mySplit = splitC[i].split(",");
  f1 = parseInt(mySplit[1],10);
  f2 = parseInt(mySplit[2],10);
  txt += (f >= f1 && f <= f2) ? mySplit[0] : "";
  txt += "\r";
}
txt

 

 

Note that this needs to be beefed up with some error checking (especially if other people will be using it) because this version will break if there isn't a layer marker or if each line of data in the marker comment isn't formatted as above...

(edit) there was a typo in 3rd to last line -- fixed now.

1 reply

Mylenium
Legend
September 27, 2021

Not really trivial, since you need to constantly compare your ranges agains current time to determine the current temporal segment. It may be simpler to just use multiple layers and hard-link them to the respective CSV data. Unless you really need to do this for hundreds of layers, this shouldn't be that hard with the added benefit that you can easily change the data when referencing the CSV directly as opposed to the old method.

 

Mylenium

Barat5E7EAuthor
Participant
September 27, 2021

Thank you for your response. However, I am not using any additional layers. The idea was to accomplish it with a single text layer (source text) for displaying the text. I had seen somewhere (lost the link to it though 😞 ) that if we put in the CSV data in a marker as comment, a variable stores the values and the expression loops through all array data through a condition comparing against current time (frame ranges) which outputs only text in the end. I had basic programming knowledge back in school but am feeling stuck now with AE syntaxs and the errors it throws at me.  Not able to put things together 😞 Any help would be appreciated.

 

 

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
September 28, 2021

If you put your data in a layer marker comment like this

 

Text_1, 10, 50
Text_2, 20, 40

 

Then an expression like this should work:

c = marker.key(1).comment;
splitC = c.split("\r");
txt = "";
f = timeToFrames(time);
for (i = 0; i < splitC.length; i++){
  mySplit = splitC[i].split(",");
  f1 = parseInt(mySplit[1],10);
  f2 = parseInt(mySplit[2],10);
  txt += (f >= f1 && f <= f2) ? mySplit[0] : "";
  txt += "\r";
}
txt

 

 

Note that this needs to be beefed up with some error checking (especially if other people will be using it) because this version will break if there isn't a layer marker or if each line of data in the marker comment isn't formatted as above...

(edit) there was a typo in 3rd to last line -- fixed now.