Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Trigger Animation based on Markers with the same name on different layers

  • Trigger Animation based on Markers with the same name on different layers

  • Christopher Hesse

    December 28, 2021 at 12:48 pm

    Hi there,

    I’m working on a recurring project where I have to throw lots of subComps into one mainComp and then set keyframes on a Control Layer to trigger a random animation on another layer on each added subComp inPoint. So far I’m doing this via keyframes ( I just have to add a keyframe on a slider on the control layer and the random animation on the other layer starts), but there has to be a way to do this by adding markers on the subComps, right? I could figure it out if the markers were all set on the same layer, but I can’t figure out how to trigger the animation if the markers lie on different layers.

    This is the expression I’m currently using to trigger the random animation via keyframes, I hope it’s enough to figure out my problem:

    fadeInTime = framesToTime(thisComp.layer(“CONTROL_politicalParties”).effect(“FADE IN/OUT”)(“Slider”));
    fadeOutTime = framesToTime(thisComp.layer(“CONTROL_politicalParties”).effect(“FADE IN/OUT”)(“Slider”));
    delay = framesToTime(thisComp.layer(“CONTROL_politicalParties”).effect(“DURATION”)(“Slider”));
    wig = wiggle(thisComp.layer(“CONTROL_politicalParties”).effect(“WIGGLES PER SEC”)(“Slider”),thisComp.layer(“CONTROL_politicalParties”).effect(“amp_SPD”)(“Slider”));
    s = thisComp.layer(“CONTROL_politicalParties”).effect(“START ANI”)(“Slider”);
    if (s.numKeys > 0){
    n = s.nearestKey(time).index;
    if (time < s.key(n).time) n–;
    if (n > 0){
    t = time – s.key(n).time;
    if (t < fadeInTime)
    linear(t,0,fadeInTime,0,wig)
    else
    linear(t,fadeInTime,fadeInTime+delay+fadeOutTime,wig,value);
    }else{
    value;
    }
    }else
    value

  • Dan Ebberts

    December 28, 2021 at 3:23 pm

    If you just need your expression to look at markers on the precomp layer instead of keyframes on your control layer, you should be able to just change this line:

    s = thisComp.layer("CONTROL_politicalParties").effect("START ANI")("Slider");

    to this:

    s = marker;

  • Christopher Hesse

    January 3, 2022 at 8:54 am

    Hi Dan,

    thank you very much for your reply! This would let the expression check every preComp layer for markers? Not just on a specific one?

  • Christopher Hesse

    January 3, 2022 at 11:46 am

    I feel like I need to elaborate a little more, so I’ve snapped a screenshot that hopefully clarifies my problem.

  • Dan Ebberts

    January 3, 2022 at 11:47 pm

    Maybe like this:

    fadeInTime = framesToTime(thisComp.layer("CONTROL_politicalParties").effect("FADE IN/OUT")("Slider"));
    fadeOutTime = framesToTime(thisComp.layer("CONTROL_politicalParties").effect("FADE IN/OUT")("Slider"));
    delay = framesToTime(thisComp.layer("CONTROL_politicalParties").effect("DURATION")("Slider"));
    wig = wiggle(thisComp.layer("CONTROL_politicalParties").effect("WIGGLES PER SEC")("Slider"),thisComp.layer("CONTROL_politicalParties").effect("amp_SPD")("Slider"));
    
    tag = "trig";
    t = 999999;
    for (i = 1; i <= thisComp.numLayers; i++){
      s = thisComp.layer(i).marker;
      if (s.numKeys > 0){
        n = s.nearestKey(time).index;
        if (time < s.key(n).time) n--;
        for (j = n; j > 0; j--){
          if (s.key(j).comment == tag){
            t = Math.min(t,time - s.key(j).time);
            break;
          }
        }
      }
    }
    if (t < fadeInTime)
      linear(t,0,fadeInTime,0,wig)
    else
      linear(t,fadeInTime,fadeInTime+delay+fadeOutTime,wig,value);
  • mike kleni

    January 4, 2022 at 1:53 pm

    Can’t it be much better?

     

  • Christopher Hesse

    January 4, 2022 at 3:19 pm

    Wow, it works! Thanks so much, Dan :).

    Can you break it down for me? I’d like to know how exactly it works out. If you have the time, that is.

  • Dan Ebberts

    January 4, 2022 at 7:04 pm

    Basically, it’s two nested loops. The outer loop examines each layer in the comp. The inner loop looks at the markers for the layer currently being examined. It starts with the most recent, previous marker, and goes backwards in time until it finds a marker with the tag comment (or runs out of markers). If it finds a marker with the tag, it saves the shortest elapsed time for tag markers found on any layer and uses that value to drive the fade in/out animation.

  • Christopher Hesse

    January 17, 2022 at 12:29 pm

    So now, I’m stumped again. I’m working with the same project and wanted to adapt your expression to flip a CC composite effect from 0 % opacity to 100 %.There’s also an if clause that checks the layer’s y-position to see, if it’s been moved from a fixed position. If that is true, CC composite’s opacity is also turned on.

    I get an error message that “startTime” is not defined and might lie outside of the array’s valid space. But I think, that’s not all that is wrong here.

    Here’s the code:

    startTime = thisLayer.inPoint;

    truePos = thisComp.layer(“CONTROL_politicalParties”).transform.position[1];

    tag = “full”;

    t = 999999;

    for (i = 1; i <= thisComp.numLayers; i++){

    s = thisComp.layer(i).marker;

    if (s.numKeys > 0){

    n = s.nearestKey(time).index;

    if (time < s.key(n).time) n–;

    for (j = n; j > 0; j–){

    if (s.key(j).comment == tag){

    t = Math.min(t,time – s.key(j).time);

    break;

    }

    }

    }

    }

    if (t < startTime) {

    if (truePos == 757) {

    0;

    }else{

    100;

    }

    }

  • Dan Ebberts

    January 17, 2022 at 4:57 pm

    A couple of things–don’t use startTime as a variable name, it’s a reserved word, so use tStart or something similar. Also, the if clause you added at the end doesn’t get entered after the layer’s in point, so it will have no visible effect on anything, and finally with that if clause at the end, your expression doesn’t have an ending value after the layer’s in point, so you probably need to add an else clause. Not sure exactly what you’re trying to do, so I can’t be more specific…

Viewing 1 - 10 of 10 posts

Log in to reply.

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