Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Running an expression a single time

  • Running an expression a single time

  • Nickolas Howell

    September 7, 2018 at 9:56 pm

    Hey everyone!
    New to the community.

    I’m working on some JSON related expressions that need to sort through a list.
    Once the list is large (10k+ items) this can become quite tedious and I believe the sort runs on every individual frame.

    Is there a way for me to run the expression a single time?
    Can I use valueAtTime() or something similar to trick after effects?

    Thanks for the assistance!
    Nick

    data = footage("JSON-Input.json").sourceData.data;
    var arr = [];

    for (obj in data) {
    arr.push(data[obj].high);
    }

    Math.max.apply(null, arr);

  • Dan Ebberts

    September 8, 2018 at 12:00 am

    Supposedly, you can limit an expression’s execution to exactly once by including this comment in the expression:

    // cacheCompareSamplesPerSecond 0

    I can’t personally verify that it works, but it was in the release notes for AE CC 2014.

    If it works for you, please report back.

    Dan

  • Nickolas Howell

    September 8, 2018 at 12:30 am

    Thanks Dan!

    This is an interesting find but I don’t seem to get any performance improvement from it.

    After it seemingly didn’t work, I decided to test it on an ease function to test if it would cause the ease functions first value to become stale throughout the rest of the timeline and it did not.

    It was still worth a shot!
    Nick

  • Nickolas Howell

    September 8, 2018 at 2:21 am

    Update:

    Dan,

    That command actually gave me an 800% speed increase!
    It turned out I had to use a very simple line of a code for it to work. Anything complex or potenially dynamic, and the line would disable itself it seemed. I ended up taking single execution pieces of math inside variable output expressions and putting them into slider controls. From there I could use the snippet you gave me and it would execute a single time. Then I could reference the slider in my main code.

    Thanks for the help!
    Nick

  • Dan Ebberts

    September 8, 2018 at 6:05 am

    Good to know. Thanks for the info!

    Dan

  • Marius Ihlar

    August 13, 2020 at 7:02 am

    Hi there!

    Checking through the internet for this question, this is the only thing I found on the topic.
    Do you remember more in detail what made it work in the end?
    I’m a noob with expressions. But i’m also trying to make my expression read every second, because right now the solution is way to slow.

    I have a list of 100 names that updates every second through looping keyframes. I would love to see my expression being calculated only 1 time per second instead of 25 times.

    This is my code:

    MyArray = footage("Members_687732 (5).csv");
    pageflipper = thisComp.layer("Page flipper").effect("Slider Control")("Slider");
    i = 0;

    //csv is one name (current)
    //MyArray is the whole array of names

    rowcount = 0;
    nameList = "";

    for (i; i < pageflipper; i++){

    csv = rowcount + 1 + ' ' + footage("Members_687732 (5).csv").dataValue([0, i]);
    rowcount++;

    //shortens too long names
    if (csv.length > 20) {

    csv = csv.substr(0,20) + "-\r" + rowcount + 1 + ' ' + csv.substr(20, 40);
    rowcount++;
    isTwoRowsName = true;
    } else {
    isTwoRowsName = false;
    }

    if(rowcount > (pageflipper - 100)) {
    if (rowcount == pageflipper - 1 && isTwoRowsName == true) {
    break;
    }
    nameList += csv + "\r";
    }
    if(rowcount >= pageflipper - 1){
    break;
    }

    }

    nameList

Viewing 1 - 6 of 6 posts

Log in to reply.

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