Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Cumulative Variable?

  • Cumulative Variable?

    Posted by Ocean Byrne on March 20, 2012 at 10:10 pm

    I want to create a variable – Cumulo – which adds the value of another parameter – Adder(which animates) – to itself on every frame.

    So on:
    frame 1 – Adder = 10 – Cumulo = 10
    frame 2 – Adder = 10 – Cumulo = 20
    frame 3 – Adder = 10 – Cumulo = 30
    frame 4 – Adder = 20 – Cumulo = 50
    frame 5 – Adder = 20 – Cumulo = 70

    How do I write an expression to do that?
    My final values will be much less user friendly to think about.

    Thanks

    Ocean Byrne replied 14 years, 1 month ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    March 20, 2012 at 10:26 pm

    Expressions can’t pass information from one frame to the next, so there aren’t any persistent variables. The best you can do is base your calculation of the global time object, or do it the brute force way and create a loop that starts at time=0 (or the layer’s in point) and re-creates everything that has happened on previous frames.

    Dan

  • Ocean Byrne

    March 20, 2012 at 10:42 pm

    So I dont think basing it on time will work for me, cause that doesnt account for the the various changes that Adder made over time.

    So how would I go about creating this loop that looks at the history of Adder and calculates Cumulo on each frame?

    Thanks for your help.

  • Dan Ebberts

    March 20, 2012 at 11:26 pm

    Probably something like this (it depends on what Adder is):


    Adder = thisComp.layer("Other Layer").transform.rotation;
    f = timeToFrames(time);
    Cumulo = 0;
    for (i = 0; i <= f; i++){
    t = framesToTime(i);
    Cumulo += Adder.valueAtTime(t);
    }
    Cumulo

    The value at each frame takes longer to execute than the frame before, so this may not be a good method for a long composition.

    Dan

  • Ocean Byrne

    March 21, 2012 at 12:36 am

    Thanks a bunch for your help Dan,

    Took some tweeking, but I got it working:

    Adder = comp("Shashkin").layer("Desert").effect("Form")("Flow Z");
    f = timeToFrames(time);
    Cumulo = 0;
    for (i = 0; i &lt;= f; i++){
    t = framesToTime(i);
    Cumulo += (Adder.valueAtTime(t) / 30);
    }
    [750, Cumulo]

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