Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions get nearestKey’s time? I think…

  • get nearestKey’s time? I think…

    Posted by Andy Engelkemier on June 22, 2009 at 2:46 pm

    Right now I have pretty much used Dan Ebbert’s expression for the pendulum and tweaked it for use on the bend effect.

    The problem I’m having is I may need this to happen in the middle of a composition. Instead of time I created another variable that = time – inpoint;. Ok that works, but that makes it to so I have to edit the layer inpoint for each layer. The inpoint may Really be related to a keyframe. I know there are a few acceptable ways to do this, but i’m trying to learn scripting as well. In my case, this works ok for now, but I’d like to know how to do it.

    So I really want to do time minus the time at the first keyframe of a time remap. I thought I could just do: time – nearestKey(t); but that’s not working. I think all nearestKey is giving me is the key index? I’m not sure how to check returned values, and I’m clicking on the error, but it won’t tell me what is wrong.

    I’m guessing I need to somehow find the time of the first key after the inPoint and subtract That value from time.

    Andy Engelkemier replied 16 years, 11 months ago 2 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    June 22, 2009 at 5:34 pm

    Something like this, probably:

    n = 0;
    for (i = 1; i <= numKeys; i++){ if (key(i).time >= inPoint){
    n = i;
    break;
    }
    }
    if (n > 0){
    t = time – key(i).time;
    if (t > 0){
    // put your pendulum code here
    }else{
    value // haven’t reached 1st keyframe after in point yet
    }
    }else{
    value // no keyframes
    }

    Dan

  • Andy Engelkemier

    June 22, 2009 at 6:18 pm

    I didn’t even think to include a catch for no keyframes, or if the keyframes were before the inPoint. I don’t know much programming, so I’m not sure what thinks like i++ are. I did gather the key(i).time part though. I just had some of the stynax wrong I guess. I’m not good at figuring out what order to put things in.

    Also, with the pendulum code….is there a way to make it faster? Because, wow that is slow. Should I be making some code that says once the value is below a certain point, just to hold the last value? Usually when the image stops moving it renders really fast. But with that expression it will never hit zero, so has to calculate every frame. That’s why it’s so slow, right?

  • Dan Ebberts

    June 22, 2009 at 7:16 pm

    What does your expression look like at this point?

    Dan

  • Andy Engelkemier

    June 22, 2009 at 7:50 pm

    It doesn’t have the cool catches like you had, but I don’t like to use those things until I understand what they are doing. I’d like to learn this stuff, but I’ve never been very good at programming….mostly because I don’t really know the math well. I need to find a book with just lots of small short examples of different math types that aren’t just related to database programming. If you know of a good suggestion, I’d put down a few bills for something that will help me out a bit.

    About the script: I just added a null object with a few slider controls so I could make some subtle changes to all of these. Right now I have 8 layers with this script as a test to show my coworker (the client in this case). I wanted a bit of randomness in a short amount of time. In other words, I didn’t want to try and figure out where I could put some random numbers because I don’t really know how those work with the min and max, or where I would even put them. I would guess I want the sin wave to start in different locations, but don’t know how to do that.
    It was ok though because simply moving the layers around just a little bit, I wanted them to start offset a bit anyway, created enough randomness that it looked ok.

    As you can see, I really didn’t change the pendulum expression much. I added some controllers, and created a variable in place of time to get time to start at the first keyframe. although, is that Really the second keyframe? I tried zero, but didn’t get good results. I’d like to know if 1 is actually the second of 2 keyframes though.

  • Dan Ebberts

    June 22, 2009 at 8:42 pm

    If you try to turn the expression off when it reaches a certain level, it still has to do the calculation. You could check your time variable against a time limit like this:

    tLim = .5;
    if (t > timLim){
    0; // or value, or whatever alternative to doing pendulum calc
    }else{
    // pendulum code here
    }

    BTW, the first keyframe is 1.

    Dan

  • Andy Engelkemier

    June 23, 2009 at 12:22 pm

    Is there a way to see what the actual errors are? The help file sounds like you are suppose to just click on the triangle-exclamation, but it’s not showing me anything.
    I tried first and noticed there was an error. But then I noticed I put tLim and then timLim for the same variable (that’s what i get for copying and pasting). I’m still getting an error after fixing that though.

    I tried the code below, but I’m getting an error.

  • Andy Engelkemier

    June 23, 2009 at 1:08 pm

    Got it….
    should I have mentioned I have cs4? They must have changed some of the global variables. It doesn’t seem you can use “t” for time and you actually have to type out “time” now.

    The time goes fairly slow until it hits 8, 7 was enough, but I wanted just a little flexibility in case I made a slight change to some of the other settings, then it just zips to the end. Exactly what I needed. That will save me quite a bit of render time.

    I thought I’d have to precompose that and do a timeremap or something to extend the time.

  • Andy Engelkemier

    June 23, 2009 at 1:26 pm

    ooops, only one more problem.
    I had to edit one line to this:
    if (time > (tLim + thisLayer.timeRemap.key(1).time)){

    so that if I moved the layer it didn’t just stop the effect completely after however many seconds. I thought to myself, “hmmm, I bet that 8 seconds is no relative to my layer.” Tested it out, and sure enough.

    Once that was updated, it was all good.

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