Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions force comp to play from the beginning with every checkbox key?

  • Dan Ebberts

    January 24, 2011 at 4:34 pm

    Try this:


    chkBx = effect("Checkbox Control")("Checkbox");

    if (chkBx.value == 0){
    0
    }else if (chkBx.numKeys == 0){
    time
    }else{
    n = chkBx.nearestKey(time).index;
    if (chkBx.key(n).time > time) n--;
    time - chkBx.key(n).time;
    }

    Dan

  • Taras Kosmachuk

    January 24, 2011 at 7:46 pm

    Hey Dan, it’s working great! Many thanks to you!!!!!

  • Cris Gundermann

    October 12, 2013 at 12:35 pm

    hi dan,

    thanks for this script (and for all the others i could find here)!
    i’m trying to combine this one with another script by you but i can’t get it to work.
    it only works with the last condition.

    i want a comp to play at random intervals but also want it to play when i activate it manually via checkbox.

    i guess it must have sth to do with how the keyframes are held,
    but when i remove the first part of the second condition and leave it like this:
    if (chkBx.value == 1){
    n = chkBx.nearestKey(time).index;
    if (chkBx.key(n).time > time) n–;
    time – chkBx.key(n).time;
    }

    … nothing will change…
    i’m not that much into expressions, so i’d be thankful if you could help me out a bit!

    thanks in advance,

    -cris

    //============================================
    //if activated, play comp at random intervals.
    //============================================
    minDur = 1;
    maxDur = 2;

    randChkBx = comp("xxx").layer("xx").effect("playRandom")("Kontrollkästchen");

    if (randChkBx.value == 1){
    seedRandom(index,true);
    t0 = inPoint + random(maxDur);
    t1 = t0 + random(minDur,maxDur);
    while(t1 < time){
    t0 = t1;
    t1 = t0 + random(minDur,maxDur);
    }
    t = time - t0;
    } else {
    value
    }

    //============================================
    //if activated, play comp, else hold on 0.
    //============================================

    chkBx = comp("xxx").layer("xx").effect("playNow")("Kontrollkästchen");

    if (chkBx.value == 0){
    0
    }else if (chkBx.numKeys == 0){
    time
    }else{
    n = chkBx.nearestKey(time).index;
    if (chkBx.key(n).time > time) n--;
    time - chkBx.key(n).time;
    }

  • Dan Ebberts

    October 12, 2013 at 4:53 pm

    I think you need to nest one of the expressions inside the other. If you wanted the playNow checkbox to have priority, you would do something like this (not tested):


    chkBx = comp("xxx").layer("xx").effect("playNow")("Kontrollkästchen");
    if (chkBx.value == 0){
    minDur = 1;
    maxDur = 2;
    randChkBx = comp("xxx").layer("xx").effect("playRandom")("Kontrollkästchen");
    if (randChkBx.value == 1){
    seedRandom(index,true);
    t0 = inPoint + random(maxDur);
    t1 = t0 + random(minDur,maxDur);
    while(t1 < time){
    t0 = t1;
    t1 = t0 + random(minDur,maxDur);
    }
    t = time - t0;
    } else {
    value
    }
    }else if (chkBx.numKeys == 0){
    time
    }else{
    n = chkBx.nearestKey(time).index;
    if (chkBx.key(n).time > time) n--;
    time - chkBx.key(n).time;
    }

    Dan

  • Cris Gundermann

    December 11, 2013 at 10:43 am

    hi,
    i totally forgot to reply and thank you.
    with your help i could achieve what i was aiming for.
    all the best

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