Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions setJustification and setText

  • setJustification and setText

    Posted by Matt Laud on January 21, 2025 at 3:43 pm

    Hi all, hitting a wall with something that seems simple. I’m using the new setJustification method in expressions, and can’t get the following to work. My intention is simply to set the text dynamically and set the justification. Working in the sourceText property of a text layer. I’ve tried a number of fixes and arrangements, but the problem is always the same: the order dictates how it is carried out, and it’s always the line that comes second that affects the layer. I can switch the lines, but it’s only the second one that works.

     

    thisComp.layer("first").text.sourceText;</p><p>style.setJustification("alignRight");

     

    I’ve tried a few fixes – setting the text layer to paragraph, using “newStyle” (though I’m not confident I’ve tried that correctly.) Even trying to set the text without referencing another layer just using quotation marks, and the issue is still the same.

     

    Adobe After Effects 2025.1.0, Macbook Pro M1 32GB Sonoma 14.7.1

    Yoan Boisjoli replied 3 weeks, 6 days ago 3 Members · 5 Replies
  • 5 Replies
  • Yoan Boisjoli

    January 21, 2025 at 3:54 pm

    Hey Matt! Are you looking for something like this?

    // Retrieve the text source from another layer
    var textContent = text.sourceText;
    // Get the current style of the layer
    var currentStyle = textContent.style;
    // Update the style with the desired justification
    var updatedStyle = currentStyle.setJustification("alignRight");
    // Combine the updated style with the text content
    updatedStyle.setText(textContent);
    // Output the final styled text
    updatedStyle;
  • Dan Ebberts

    January 21, 2025 at 4:13 pm

    I think this is all you need:

    txt = thisComp.layer("first").text.sourceText;
    style.setJustification("alignRight").setText(txt)
  • Yoan Boisjoli

    January 21, 2025 at 4:22 pm

    Hey Dan, I think you need to create a style first because setJustification(“alignRight”) creates a new TextDocument object but doesn’t apply the change directly to the style object before calling setText(txt). I think that to make sure the updated justification is applied, the style first has to be updated, then combined with the text content.

  • Dan Ebberts

    January 21, 2025 at 4:29 pm

    Actually, this seems to work:

    txt = thisComp.layer("first").text.sourceText;
    style.setText(txt).setJustification("alignRight")
  • Yoan Boisjoli

    January 21, 2025 at 4:36 pm

    Sorry Dan! I had the text in a text box so it wasn’t working! haha Also you made me realise I don’t need all that complex expression. Yours has more style hehe

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