Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Set 2 different fonts via expressions

  • Set 2 different fonts via expressions

    Posted by Yoan Boisjoli on April 28, 2022 at 2:19 pm

    Hey guys,

    I’m using expressions to have text being typed with a blinking cursor and pretty happy with it although font is set to bold so the cursor is bold. I would like it to be regular or light.

    When trying to set a different font weight only for the cursor, it gives me error.

    Is there a way to have 2 font style within the same layer/expression?

    this is what I’m currently trying:

    var txt1 = "bold";
    var txt2 = "light";
    var newStyleBold = text.sourceText.style.setFont("Silka-Bold");
    var newStyleLight = text.sourceText.style.setFont("Silka-Light");
    newStyleBold.setText(txt1) + newStyleLight.setText(txt2);

    Nick Graves replied 2 years, 7 months ago 2 Members · 1 Reply
  • 1 Reply
  • Nick Graves

    April 28, 2022 at 4:34 pm

    I’m not sure if there is a way to do it on one layer/expression, I tried with a similar project (blinking cursor and everything, actually!) and I just ended up creating a second text layer with the source text sampling the original text. I’m not sure how you decided to create your blinking cursor and how the expressions are set up for you, but for me it looks something like this:

    1. I grab the original text’s sourceText that I’ve animated with a range selector to have it reveal as it’s “typed.”

    originalText = thisComp.layer("original text").text.sourceText;


    2. Then I create a variable for the font style. (It’s been a bit since I learned how to do this, so I don’t remember the technical reason for why you need to write this.)

    newText = originalText.style;


    3. after that, I set an expression for the blinking cursor itself.

    I replace all the text with every character I would have used in the original text, using the javascript “replace” method and Regular Expressions to include all the characters I wanted. I didn’t have a procedural method for generating these characters, so instead I just ran my finger across my qwerty keyboard in order. Then I replaced all the characters with the character I chose to use for the blinking cursor, which is “W”.

    (For context on why this looks weird, I’m using a pixel style font where each character is inside an 8×8 pixel block, and then to create a 1 pixel outline around each character I created a second pixel font that is the Bold version. It just so happens that the “W” character is a solid 8×8 block, so I used that character for my blinking cursor icon.)

    newText = originalText.replace(/[qwertyuiopasdfghjklzxcvbnm,.?!' ]/gi,"w");

    then I updated this layer with a new Range Selector animation that trimmed down the text to show a single character, and then animated the “Offset” value with an expression tied to the original layers “Start” value so they would line up. Hopefully that is helpful, I’m unsure if our approaches are similar enough to solve anything on your end.

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