Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Style a single word in a text layer?

  • Style a single word in a text layer?

    Posted by Blake Goulette on March 16, 2022 at 9:36 pm

    Hi all. I have a text layer that has a blinking cursor (based on this YT tutorial: This is fine as far as it goes (I did fix it so it’ll still work on newlines), but I have a text layer that has an italic variant at one point, and the above script makes everything the same font as the initial font in the layer.

    The script splits the text apart and gradually rebuilds it: it’s my hope that there’s some magical variant of setStyle that allows you to specify start and stop indexes for where to apply a different style? Or am I just straight out of luck? Thanks!

    Of course, if there’s a better way to create a cursor effect in the first place, I’d love to know that, too!!!

    Some contents or functionalities here are not available due to your cookie preferences!

    This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.

    Yoan Boisjoli replied 4 months ago 5 Members · 9 Replies
  • 9 Replies
  • Nick Graves

    March 16, 2022 at 9:57 pm

    Not totally sure of how you’ve laid out your file in comparison to the tutorial, but if you are looking to get the indices of particular characters you could try the javascript search() method:

    then use that to setStyle on those particular characters that match.

  • Blake Goulette

    March 16, 2022 at 10:00 pm

    Thanks Nick. The search() method could be useful. It’s something I’ll definitely consider the next time this comes around: for now, since this is due soon (ha!), I cheated and made two layers: one all regular, one all italic, and masked the exclusive portions. It happens quickly enough and it’s a short enough word (“and”) that the kerning doesn’t get too screwy, so…yeah 🙁

  • Nick Graves

    March 16, 2022 at 10:10 pm

    yeah that’s sometimes the only way to get stuff out the door, especially if it’s new territory. I found when I was messing with setStyle expressions (which was actually very recent which is why this thread peaked my interest) that there are some “unspoken rules”. For example I’m not sure how to stitch multiple strings together with different font style settings on them in a single text layer, you may have to create multiple string variables, set the font styles, and then stitch them back together at the end, like “textA + textB + textC;”

    Interesting problem and also pretty cool tutorial!

  • Filip Vandueren

    March 17, 2022 at 9:13 am

    Hi there,

    it’s not possible to set multiple styles in 1 sourceText object, you can getStyleAt() for a particular character, but you can only set style for the whole layer.

    Unfortunately, this also means that if you manipulate the sourceText in any form (like add a “|” string to the end), the style of the entire sourceText gets changed to the styling of, I believe, the first character.

  • Blake Goulette

    March 17, 2022 at 3:25 pm

    Thanks Filip. That’s what I was afraid of, but hope springs eternal 😉 Thanks for weighing in! Like I told Nick, I settled for faking it!

  • Kevin Camp

    March 18, 2022 at 9:43 pm

    If you needed to do this again, you can do it with a couple text animators, which would allow you to format the text any way you needed — adding italic or bold words, or even changing the font as needed.

    To do it with animators, you can start by simply adding the typewriter animation preset (animation presets>text>animate-in). At this point the text should type on if you scrub thru the timeline.

    Next, you need to add an extra character to the end of your text, it doesn’t matter what the character is, but it cannot be a space. This character will get replaced in the next step.

    Then create a new text animator on the same text layer for Character Value and set the value to 124 (this is the pipe, or vertical line). Then use an expression on that animator’s Offset property to link it to the Offset of the Typewriter preset, but one character shorter, so it will look like this:

    text.animator("Animator 1").selector("Range Selector 1").offset - 100 / text.sourceText.length

    Now the text should type on with a vertical cursor at the end as it types on.

    To make the cursor blink, add this expression to the character value property:

    blink = 1 ; // value in seconds
    if( time % blink > blink / 2 ) { 124 } else { 1 }

    And then twirl down the animator’s settings to get to advanced>smoothness and set that to 0.

    Your text should now type on with a blinking cursor.

    Now save it as a preset : )

  • Blake Goulette

    March 18, 2022 at 9:45 pm

    Thanks Kevin! I’ll definitely give this a look…Later. I’m done with this project for today! 🙂

  • Filip Vandueren

    March 19, 2022 at 7:21 am

    Hi Kevin,

    A few downsides of using a textanimator: that solution would cause the cursor to follow the styling of the character, so it would become, bold, italic, change color, change fonts… together with the text.

    And it can’t be visible while it is on a white space character (like you mentioned, that’s why the final character can’t be a space…)

    I don’t really know of a simple method that combines the best of both approaches (sourceText vs text animator), the fact that the character off-set ignores white space is a real problem…

  • Yoan Boisjoli

    October 25, 2023 at 12:43 am

    I’ve made a feature request here. If you think this would be useful, I invite you to vote for it.

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