Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions per-character styling

  • per-character styling

    Posted by Adam Greenberg on November 20, 2024 at 4:48 pm

    Hi everyone.

    I have a question about making this new feature useful in a template.

    Imagine a text layer that says something like Monday 9 p.m.

    and the day is a different font from the hour. In my current templates I have 2 seperate text layers and expressions control the position of these 2 layers accordingly so that the user only has to edit these 2 texts and not worry about moving either of them.

    Now imagine this could also appear as mondays to thursdays 7:30 p.m.

    Is there a way that this new feature in after effects that allows you to use 2 fonts in the same layer even though it doesnt know how many words the first font would be ? Or am I better off using my current method ?

    also, the ”hour” part of this layer could say noon or midnight ( for example ) so I couldn`t add any conditional statements that looks for a number.

    thanks for any insight on this relatively new feature

    Dan Ebberts
    replied 3 weeks, 1 day ago
    3 Members · 3 Replies
  • 3 Replies
  • Yoan Boisjoli

    November 20, 2024 at 5:11 pm

    Hey Adam! Basically what it does now is that you can feed the expression the length of the text (how many characters are in the text) so that the expression know how many characters should have the specific style (font in this case) that you want.

    My favorite way of doing this is to have 2 text layers (i.e. day and time) that drives a main layer where everything is assembled. So the main layer looks for the length of each layers so that way, no matter how many characters you have in the day, it will be in the right font.

    I will usually feed the Day and Time source text to the essential graphic’s panel. That way it’s easier for the editor to replace the day and time individually. You could also go one step further and have both be controlled by a drop down menu.

    Here’s an exemple:

    // Get text from the driving layers

    // Get text from the driving layers

    var dayText = thisComp.layer("Day").text.sourceText.value;

    var timeText = thisComp.layer("Time").text.sourceText.value;

    // Combine the text

    var fullText = dayText + " " + timeText;

    // Define styles

    var baseStyle = text.sourceText.style.setFont("ArialMT"); // You need to specify a default style first so you can change it later

    var dayStyle = baseStyle.setFont("B612Mono-Regular", 0, dayText.length); // Day font

    var timeStyle = dayStyle.setFont("Boldstrom", dayText.length + 1, timeText.length); // Time font

    // Apply combined styled text

    timeStyle.setText(fullText);

  • Adam Greenberg

    November 20, 2024 at 6:23 pm

    thanks so much, Im going to try it out

  • Dan Ebberts

    November 20, 2024 at 7:21 pm

    If there’s always a space between the day and the time, you could use a single source layer, like this:

    txt = thisComp.layer("Day Time").text.sourceText.value;
    L1 = txt.split(" ")[0].length;
    L2 = txt.substr(L1+1).length;
    style.setFont("ArialMT",0,L1).setFont("Arial-Black",L1+1,L2).setText(txt)

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