Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Is it possible to combine two properties from textSource into new text layer?

  • Is it possible to combine two properties from textSource into new text layer?

    Posted by Paul Beckett on March 2, 2020 at 3:03 pm

    Hi smart people of Creative Cow…

    I have been playing around with the new font style expressions now available in Ae cc2020. Now it might be my terminology which is letting me down or my super tired dad brain but I am finding it hard to find clear information on how to combine two properties from a single textSource property from a user text layer into a textSource on another text layer.

    What I would like to achieve is to get the width of a single specific character from a string entered by the user on a text layer, I also need to parse the style of the font using the new style or getStyleAt() expression, so the single specific character dynamically changes with any change made to the user input text and an change made to the font style itself. This is so that I can eventually apply an effect to that specific character which is based on the width of that character.

    Example:

    I want to isolate the “X” from the word “TEXT” and apply an effect based on the width of the “X” to that character.

    I can do this using:

    a = thisComp.layer(“User Text”).text.sourceText.charAt(2);

    Which gives me just the “X” and a bounding rectangle the size of the “X”.

    I also want to parse the style of the font in the user text layer by using:

    b = thisComp.layer(“User Text”).text.sourceText.getStyleAt(0);

    On it’s own this expression will parse the font style okay. However I need to combine the two expressions (a and b). Sadly every combination I try either results in an error or no error but no text is not displayed, just a blank text layer.

    How would I combine these two, if possible?

    a = thisComp.layer(“User Text”).text.sourceText.charAt(2);
    b = thisComp.layer(“User Text”).text.sourceText.getStyleAt(0);

    Normally this isn’t an issue, with for example, numbers as it is just a case of math, but with textSource I’m a little bit lost….

    Many thanks!

    P.

    a = thisComp.layer("User Text").text.sourceText.charAt(2);
    b = thisComp.layer("User Text").text.sourceText.getStyleAt(0);

    //a.b?
    //a + b?

    Jesse Kerman replied 3 years, 11 months ago 4 Members · 7 Replies
  • 7 Replies
  • Alex Printz

    March 2, 2020 at 5:18 pm

    It looks like defining the style has to be first, and then the actual content is a subset of the style. I’m going to dig a bit more into this, haven’t looked much at the new style expressions much, and there’s hardly any documentation.

    a = thisComp.layer("User Text").text.sourceText.charAt(2);
    b = thisComp.layer("User Text").text.sourceText.getStyleAt(0);

    style = b;
    style.setText(a);

    OR

    thisComp.layer("User Text").text.sourceText.getStyleAt(0).setText(thisComp.layer("User Text").text.sourceText.charAt(2));

    Alex Printz
    Mograph Designer

  • Paul Beckett

    March 3, 2020 at 8:41 pm

    Hi Alex,

    That did it! Thanks so much for taking the time to help out!

    P.

  • Patrick Grossien

    March 5, 2020 at 5:58 pm

    Hey Paul & Alex,

    I am trying to access the line spacing via getStyleAt.
    But I always keep getting the error that getStyleAt is not a function.

    thisComp.layer("TextLayer").text.sourceText.charAt(2)

    for example works fine, but

    thisComp.layer("TextLayer").text.sourceText.getStyleAt(2)

    returns the error.

    I tried to debug by putting the code into a sourceText of a second layer, so I can get a visual of the returned data. So far no luck.

    I’m working with 17.0.4 CC.

    Any hints on how to make use of these new expressions?

    Thanks a ton!
    Patrick

    thisComp.layer("TextLayer").text.sourceText.getStyleAt(2)

  • Alex Printz

    March 5, 2020 at 6:08 pm

    Make sure you’re using the newer Javascript expression engine, not extendScript. Style attributes are only available there.

    Alex Printz
    Mograph Designer

  • Patrick Grossien

    March 5, 2020 at 6:19 pm

    Oh man, thanks a ton! I guess I missed the memo on that! ????

    Patrick

  • Alex Printz

    March 5, 2020 at 6:31 pm

    I don’t think extendScript is being updated; Javascript is the new engine that everything will be developed in moving forward.

    Alex Printz
    Mograph Designer

  • Jesse Kerman

    February 27, 2021 at 4:50 am

    I just wanted to say thanks Alex because this post helped me out a ton. I don’t know why Adobe’s text expressions documentation doesn’t explain this… seems like a basic thing people might need to know — that the text content is a subset of the style. ?‍♂️

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