Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions getstyleat() & setText() returns [object Object]

  • getstyleat() & setText() returns [object Object]

  • Philip Peterson

    May 6, 2021 at 11:49 am

    I’m trying to parent multiple text layers from multiple comps into 1 comp and keep their individual size and color. But what I tried and/ or found on several websites (including Adobe’s “Express yourself (and your text)”) doesn’t work.

    Here’s one of the many that I tried:

    TXT1 = comp("TXT1").layer("TXT1").text.sourceText
    TXT2 =comp("TXT2").layer("TXT2").text.sourceText
    a = TXT2.getStyleAt(0,0);
    TXTcombined = a.setText(TXT2);
    txt = TXTcombined + ' ' + TXT1;

    The result I get is:

    [object Object] TXT1

    with an unchanged text style.

    I also tried using “var” or “const” for TXT2 and a -> Same result.

    On the Adobe website it says:

    style = thisComp.layer(“Parent”).text.sourceText.getStyleAt(0); style.setText(thisComp.layer(“Parent”).text.sourceText);

    Same result.

    I also tried to add the .style prefix like in Adobe’s example -> same result.

    TXTcombined = TXT2.getStyleAt(0,0).setText(TXT2);

    Same result.

    There are some other help sites & videos, that state basically the same Expression over and over again and they all result in the same outcome for me. Only thing that’s different is, that they have their text layers in the same comp. But that shouldn’t be an issue?

    So either I’m missing something or there has to be a new/ other way to get the text style + source text from another layer. I’m using AE 2020 and Javascript is enabled.

    Has anyone experienced the same issue and/ or knows how to fix it?

  • Trent Armstrong

    May 6, 2021 at 1:17 pm


    You are not alone in thinking this is a tricky one. I still have to scour the docs to make sure I’m getting the order and formulae right just about every time I use these new text style expressions.

    I think I’ve got something here that will work for you (please let me know if it needs to be different).

    TXT1 = comp("TXT1").layer("TXT1").text.sourceText;
    TXT2 = comp("TXT2").layer("TXT2").text.sourceText;
    txt = TXT2 + ' ' + TXT1;
    const style = TXT2.getStyleAt(0,0);

    I’m going to explain what’s happening in each spot. You may already understand some of this, so bear with me.

    • The two variables TXT1 and TXT2 are pulling the text.sourceText value from the TXT1 and TXT2 text layers in their respective comps.

    • “txt = TXT2 + ‘ ‘ + TXT1 ” is building a new variable out of the two previously defined variables as a string of text—with a space in between the two pieces of text.

    • “const style = TXT2.getStyleAt(0,0)” tells this particular text layer to store the style of the text from the layer “TXT2” of the comp “TXT2”.

    • “style.setText(txt)” <— This was the tricky one for me. It sets the style for this text layer with the “style” command and then sets the actual text string of the layer to the value of “txt”. So the order is Get a style/Create a Style and then apply that Style to what you set as the text of the layer.

    \/ The area below is me trying and failing at formatting code \/ 😉

  • Philip Peterson

    May 6, 2021 at 1:53 pm

    Hi Trent!

    Thanks for your code & explanation! Glad that this is a common problem, makes me feel better about myself.

    I’ve noticed, that I made my desired result a bit misunderstable (language barrier, I’m trying my best).

    I need txt2 to be changed in color, size and font independently from txt1. Something like this:

    txt2 txt1

    Your code puts them together into the style property of txt2.

    txt2 txt1

    Also, I’m using an expression that I stole from Dan (I think), that creates an automated line break after n characters.

    n = 50;
    outStr = "";
    newLine = ""
    splt = txt.split(" ")
    for (i = 0; i < splt.length; i++){
    if ((newLine + " " + splt[i]).length > n){
    if (outStr != "") outStr += "\r";
    outStr += newLine;
    newLine = splt[i];
    if (newLine != "") newLine += " ";
    newLine += splt[i];
    if (newLine != ""){
    if (outStr != "") outStr += "\r";
    outStr += newLine;

    I get an error at .split, because (as I just learned from reddit, don’t quote me on that) the product of setText is not a string, but a textstyle property.

    Do you know a way around that? I would need to convert style.setText(txt2) to a string before chaining it together with txt1 and then send it into that line break expression.

    Thank you!

  • Trent Armstrong

    May 6, 2021 at 3:41 pm


    This is another common concern. Sadly, at the present time, it’s not possible to mix text styles through the “style” expression. The best thing to do is have two separate text layers with two different styles you then place using expressions. There should be another thread here for causing two text layers to be placed in relationship to each other.


  • Philip Peterson

    May 6, 2021 at 4:19 pm

    That’s a shame.

    Positioning them next to each other was actually my plan B, just thought there would be an easier way, because when there’s a line break in txt1 the new line needs to line up with the first letter of txt2 . Guess I’ll have to use the good old spacebar in front of txt1 to make room for txt2 or try sourcerectattime to calculate the width of txt2 and convert that into spaces.

    Anyway, thank you!

Viewing 1 - 5 of 5 posts

Log in to reply.

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