Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions style.setFont not working with toString

  • style.setFont not working with toString

    Posted by Ayush Tanna on August 14, 2020 at 8:04 pm

    Hi,
    I was trying something out by taking the rgb values from an image and changing the color of the text layer to that color. I am also taking the hex code of that color and displaying as text in the same text layer. But when I try to add other fonts using the setFont feature introduced in v17 it stays the same. I can still change the font from the character panel though.

    Any help is appreciated.

    Thanks in advance
    Ayush

    var array = [
    "Metropolis-Regular",
    "Didot-Bold",
    "Roboto-BoldCondensed"
    ];

    text.sourceText.style.setFont(array[1])

    r = Math.round(text.animator("Animator 1").property.fillColor[0]*255).toString(16);
    if (r.length < 2) r = "0" + r;
    g = Math.round(text.animator("Animator 1").property.fillColor[1]*255).toString(16);
    if (g.length < 2) g = "0" + g;
    b = Math.round(text.animator("Animator 1").property.fillColor[2]*255).toString(16);
    if (b.length < 2) b = "0" + b;

    '#' + r + g + b;

    Ayush Tanna replied 6 years ago 2 Members · 2 Replies
  • 2 Replies
  • Andrei Popa

    August 15, 2020 at 6:25 am

    Try this


    var array = [
    "Metropolis-Regular",
    "Didot-Bold",
    "Roboto-BoldCondensed"
    ];

    r = Math.round(text.animator("Animator 1").property.fillColor[0]*255).toString(16);
    if (r.length < 2) r = "0" + r;
    g = Math.round(text.animator("Animator 1").property.fillColor[1]*255).toString(16);
    if (g.length < 2) g = "0" + g;
    b = Math.round(text.animator("Animator 1").property.fillColor[2]*255).toString(16);
    if (b.length < 2) b = "0" + b;

    text.sourceText.style.setFont(array[1]).setText('#' + r + g + b);

    Andrei
    My Envato portfolio.

  • Ayush Tanna

    August 15, 2020 at 6:52 am

    Hi, Andrei

    Thanks so much for this. It works perfectly!

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