One text layer to change text in multiple layers

Moderators: Disciple, zlovatt

Post Reply
fahdchishty
Posts: 4
Joined: January 6th, 2015, 10:48 am

January 7th, 2015, 12:17 am

I had been looking for some expression that would allow me to change multiple text layers while I (or any other user) would need to change only 1 layer.

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 :D

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;
}
fahdchishty
Posts: 4
Joined: January 6th, 2015, 10:48 am

January 7th, 2015, 6:51 am

There is a little modification that is required to use the expression effectively. When you create the source layer, you need to add another return line (press enter).
If that is not done, the last and the second last word get a bit jumbled up.

Attached is the file that shows working of this code :)
Attachments
sample_word_selector.zip
CS 6 File
(8.1 KiB) Downloaded 182 times
Post Reply