Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions One text layer to change text in multiple layer

  • One text layer to change text in multiple layer

    Posted by Fahd Chishty on January 6, 2015 at 5:45 pm

    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 made the following expression that you need to put in the word layer, mentioning which word number you want to pick from the source.

    Hope it helps someone else 🙂

    charNum = 2; //The index of word which you want to take
    totChars=12; //Total Number of characters in the sentence (excluding \r)
    totWords=4; //Enter how many words there are in the sentence
    //defining other variables
    cont=true;
    count=0;
    i=0;
    j=0;
    txt=[];
    totChars=totChars+totWords-1;
    myLayer=thisComp.layer("Change Text Here");
    while(cont && i=charNum)
    {
    cont=false;
    break;
    }
    }
    txt[j]=myLayer.text.sourceText[i];
    i++;
    j++;

    }
    txt.join("");

    Fahd Chishty replied 11 years, 4 months ago 1 Member · 1 Reply
  • 1 Reply
  • Fahd Chishty

    January 7, 2015 at 2:35 pm

    The code above needed some enhancements and tweaking for working right.

    I am putting the modified code here for any who might need it 🙂

    charNum = 1; //The index of word which you want to take
    myLayer=thisComp.layer("Change Text Here");
    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=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;
    }

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy