To explain my point, I had a composition in which there were 5 words in 5 different layers with different animations. In order to change a word, I had to look up all its layers and change them. I wanted 1 text layer, which would act as a source and all the word layer would take its source text.
So I am working on the following expression that you need to put in the word layer, mentioning which word number you want to pick from the source.
Any help would be appreciated

Code: Select all
myLayer=thisComp.layer("Change Text Here");
charNum = 5; //The index of word which you want to take
totChars=myLayer.text.sourceText.value.length; //Total Number of characters in the sentence (excluding \r)
totWords=getWords(myLayer); //Number of words there are in the sentence
//defining other variables
cont=true;
count=0;
i=0;
j=0;
fJ=0;
txt=[];
while(cont && i<totChars){
if (myLayer.text.sourceText[i]=="\r")
{
count++;
fJ=j;
j=0;
i++;
if(count>=charNum)
{
cont=false;
break;
}
}
txt[j]=myLayer.text.sourceText[i];
i++;
j++;
}
fJ;
txt.splice(fJ, (txt.length-fJ));
txt.join("");
function getWords(layer)
{
x=0;
y=0;
while (x<totChars)
{
if (layer.text.sourceText[x]=="\r")
{y++;}
x++;
}
return y+1;
}