Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Need to customize Dan’s Counter Expressions script

  • Need to customize Dan’s Counter Expressions script

    Posted by Roland R. kahlenberg on March 24, 2014 at 9:58 pm

    Here’s the script – https://www.motionscript.com/design-guide/counter.html.

    I’ve got the script written as such –

    var x ="" ;
    for (j=0; j<12; j++)
    {
    valLength = myArray[j].length;
    var s = myArray[j];
    if (commas){
    decimals = " ";
    if (Ndecimals > 0){
    var decimals = s.substr(-(Ndecimals + 1));
    s = s.substr(0,s.length - (Ndecimals + 1));
    }
    outStr = s.substr(-s.length, (s.length-1)%3 +1);
    for (i = Math.floor((s.length-1)/3); i > 0; i--){
    outStr += thousandSeparator + s.substr(-i*3,3);
    }
    x=x + prefixArray[j] + outStr + decimalSeparator + myArray[j].substr(valLength-Ndecimals) + suffixArray[j] + "\r"
    }
    }

    All works well but I would now like to add conditionals to check if prefixArray[j]and/or suffixArray[j] are enabled. These two arrays are originally contained in their respective layers – reading their data is thus far accurate and working as expected. I would like a user to disable (switch off their visibility switch) the layers, independently , should they not want one or both of these arrays as part of the final line in the existing script (above).

    I’m having difficulty incorporating the if…then conditionals required to pull this off.

    TIA
    RoRK
    Latest AE Workshop – MoGraph Intensity – Shapes & Text

    Intensive mocha & AE Training in Singapore and Other Dangerous Locations

    Imagineer Systems (mocha) Certified Instructor
    & Adobe After Effects CS6 ACE/ACI

    Roland R. kahlenberg replied 12 years, 1 month ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    March 24, 2014 at 10:45 pm

    I haven’t tested it, but you should be able to change the last part to something like this:

    prefix = thisComp.layer(“prefixArray”).transform.opacity > 0 ? prefixArray[j] : “”;
    suffix = thisComp.layer(“suffixArray”).transform.opacity > 0 ? suffixArray[j] : “”;
    x=x + prefix + outStr + decimalSeparator + myArray[j].substr(valLength-Ndecimals) + suffix + “\r”
    }
    }

    Dan

  • Roland R. kahlenberg

    March 24, 2014 at 11:08 pm

    Thanks Dan, I actually got it to work by inserting the if ..then conditionals before the last line of your code I posted. However, I needed four lines of code to cover each of the four possible permutations.

    I also used
    prefix = thisComp.layer("prefixArray").enabled ==1 as my condition.

    Your solution works and is of course a lot more elegant. Can you explain what this part

    ? prefixArray[j] : "";

    of your script does?

    Thanks
    RoRK
    Latest AE Workshop – MoGraph Intensity – Shapes & Text

    Intensive mocha & AE Training in Singapore and Other Dangerous Locations

    Imagineer Systems (mocha) Certified Instructor
    & Adobe After Effects CS6 ACE/ACI

  • Dan Ebberts

    March 24, 2014 at 11:17 pm

    It’s just a compact form of if/else.

    This:

    prefix = thisComp.layer(“prefixArray”).transform.opacity > 0 ? prefixArray[j] : “”;

    is equivalent to this:

    if (thisComp.layer(“prefixArray”).transform.opacity > 0)
    prefix = prefixArray[j]
    else
    prefix = “”;

    Dan

  • Roland R. kahlenberg

    March 24, 2014 at 11:24 pm

    AWESOME Dan!!! That’s an incredibly handy shortcut!

    Cheers
    RoRK
    Latest AE Workshop – MoGraph Intensity – Shapes & Text

    Intensive mocha & AE Training in Singapore and Other Dangerous Locations

    Imagineer Systems (mocha) Certified Instructor
    & Adobe After Effects CS6 ACE/ACI

  • Roland R. kahlenberg

    April 9, 2014 at 4:50 am

    Hi Dan, I’ve hit a snag. I’m getting unwanted results with negative values. Here’s the script again –

    var x ="" ;
    for (j=0; j<12; j++)
    {
    valLength = myArray[j].length;
    var s = myArray[j];

    if (commas){
    decimals = " ";
    if (Ndecimals > 0){
    var decimals = s.substr(-(Ndecimals + 1));
    s = s.substr(0,s.length - (Ndecimals + 1));
    }
    outStr = s.substr(-s.length, (s.length-1)%3 +1);
    for (i = Math.floor((s.length-1)/3); i > 0; i--){
    outStr += thousandSeparator + s.substr(-i*3,3);
    }
    prefix = comp("Enter Textual Data Here - MultiSegment Bar").layer("Controller").effect("Use Prefix")("Checkbox") ==1 ? prefixArray[j] : "";
    suffix = comp("Enter Textual Data Here - MultiSegment Bar").layer("Controller").effect("Use Suffix")("Checkbox") ==1 ? suffixArray[j] : "";
    x=x + prefix + outStr + decimalSeparator + myArray[j].substr(valLength-Ndecimals) + suffix + "\r";
    }
    }

    When the input value is -700.00, I get the following result $-,700.00. I was hoping to get -$700.00.

    For 4-digit numbers, if the input is -1500, I get the following result $-1,500.00. For a 5-digit number such as -70,000, I get $-70,000.00.

    TIA
    RoRK
    Latest AE Workshop – MoGraph Intensity – Shapes & Text

    Intensive mocha & AE Training in Singapore and Other Dangerous Locations

    Adobe After Effects CC ACE/ACI
    Imagineer Systems (mocha) Certified Instructor

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