Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Combining 2 Expressions

Tagged: 

  • Combining 2 Expressions

    Posted by Patrick Schmid on February 6, 2023 at 11:40 pm

    Hi,

    im trying to combine those 2 Expressions…

    can anybody help me out? 🙂

    + add a option for Decimals?

     

    1st Expression for changing the font of the Text-Layer:

    var fontArray=[

    “BerninaSansOffc-Regular”,

    “DTFlowTextV1.011-Regular”

    ]

    v=Math.round(thisComp.layer(“Null 19”).effect(“Font CTRL”)(“Slider”))

    style.setFont(fontArray[v]);

    2nd Expression is a Counter with a Point Control because i need numbers greater then 1million:

    num = Math.round(effect(“Point Control”)(“Point”)[0]);

    function addCommas(x) {

    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g,”,”);

    }

    addCommas(num)

     

     

    Filip Vandueren replied 1 year ago 3 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    February 7, 2023 at 1:19 am

    Try this:

    num = Math.round(effect("Point Control")("Point")[0]);
    function addCommas(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");
    }
    txt = addCommas(num);
    var fontArray=[
    "BerninaSansOffc-Regular",
    "DTFlowTextV1.011-Regular"
    ];
    v=Math.round(thisComp.layer("Null 19").effect("Font CTRL")("Slider"));
    style.setFont(fontArray[v]).setText(txt);
  • Filip Vandueren

    February 7, 2023 at 2:18 pm

    Instead of the custom addCommas() method you can also use the built-in method:

    num.toLocaleString('en-us');

    and if you want decimals, don’t use Math.round() in the first line but:

    num = effect("Point Control")("Point")[0];
    txt = num.toLocaleString('en-us', {maximumFractionDigits: 2});

    This will limit it to max 2 decimal digits.

    if you always want 2 decimals (123.00) then:

    txt = num.toLocaleString('en-us', {minimumFractionDigits: 2, maximumFractionDigits: 2});

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