Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions trying to run time mapped animation when null object position changes

  • trying to run time mapped animation when null object position changes

    Posted by Gregor Knell on May 7, 2013 at 5:02 pm

    Hey all,
    I have a 6 frame animation within a time remapped layer named “Blue” that I’m trying to run one time every time a null object changes position.

    I have the time remap attached to a slider and I have the Null object keyframes set to “Hold” so the position only changes on a new keyframe.

    With my weak knowledge of expressions and sliders, this is what I’ve come up with so far:

    n1 = thisComp.layer("Null 1");
    thisframe = n1.position.valueAtTime(time);
    prevframe = n1.position.valueAtTime(time - thisComp.frameDuration);

    if (thisframe != prevframe) {

    [ go to frame 1 of "Blue" and run 6 frames ]

    }

    My two issue:
    1.) I haven’t been able to find how to tell “Blue” to go to frame 1 and run 6 frames and then stop. Is this a loopin expression?

    2.) Despite both “thisframe” and “prevframe” displaying the correct values, my if statement does not work when tested.

    Any tips or advice would be greatly appreciated!
    Best,
    G

    Dan Ebberts replied 13 years ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    May 7, 2013 at 5:58 pm

    If you just need your 6-frame sequence to run at each of Null 1’s position keyframes, something like this should work:


    p = thisComp.layer("Null 1").transform.position;
    n = 0;
    if (p.numKeys > 0){
    n = p.nearestKey(time).index;
    if (p.key(n).time > time) n--;
    }
    if (n > 0){
    t = time - p.key(n).time;
    Math.min(t,framesToTime(5))
    }else{
    framesToTime(5);
    }

    Dan

  • Gregor Knell

    May 9, 2013 at 2:01 am

    Dan,
    Thanks so much for the help, that’s exactly what I was looking for!
    Now just to dissect it!

    All the best,
    Gregor

  • Gregor Knell

    May 10, 2013 at 6:15 pm

    Hey Dan,

    I took your code and tried to take it a step further for what I’m looking to do but ran into an issue.

    I’m trying to have a number of time remapped layers responding to multiple keyframes on the same null object. I’ve condensed 30 minutes of keyframes down into 5 minutes so there’s a lot of keyframes between frames.

    This gets a bit confusing but within each frame, I’d like to sequentially send the keyframes to the time remapped layers. I hope that makes sense? Seeing what I’m doing in the code might help more.

    The code works sometimes but then, regardless of where I am in the composition, I get this warning: Bad method arguments: This property has no keyframe numbered 8072, expression disabled. Error occurred at line 13.

    (the null object has 8071 keyframes)

    I’ve marked the things that I’ve added to you code with what I think they do based on my tests.

    Any advice or strategy on how to approach this would be greatly appreciated.
    All the best,
    Gregor

    p = comp("12").layer("Null 1").transform.position;
    n = 0

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

    d = comp("Bulk").layer(index).index; // Current Layer index number.
    v = (n+d-1); // Next keyframe index number to effect.
    c = p.nearestKey(time).time; // Time of current keyframe.
    n = p.key(v).time; // Time of next keyframe.

    if ((n-c) < (1/23.976)){ // If the time between the current keyframe and the next one is less then 1 frame (1/23.976)...
    t = time - p.key(v).time;
    Math.min(t,framesToTime(5))
    } else {
    framesToTime(5);
    }

  • Dan Ebberts

    May 10, 2013 at 6:34 pm

    It looks like v can exceed the number of keyframes. I’m not sure what you want to do in that case, but you could eliminate the error message by doing something like this:

    v = Math.min((n+d-1),p.numKeys);

    Dan

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