Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Skipping marker to adjust opacity

  • Skipping marker to adjust opacity

    Posted by Dave Gorrie on December 1, 2014 at 11:26 pm

    Hi All – I have a working expression for going to the next marker to either fade in/out – but I’d like to skip a marker and go a few key frames….I can’t wrap my head around where I would add that in!

    Here is the original code:
    action = comp("General Settings").layer("Coordinates");
    mf = comp("General Settings").layer("General Settings").effect("Markes Fade Out Time")("ADBE Slider Control-0001");
    n = 0;
    if (action.marker.numKeys > 0){
    n = action.marker.nearestKey(time).index;
    if (action.marker.key(n).time > time){
    n--;
    }
    }

    if (n == 0){
    0;
    }else{
    try{
    t = action.marker.key(n).time;
    tNext = action.marker.key(n+1).time;
    if (action.marker.key(n).comment == "s1") ease(time,tNext,tNext,0,100) else 0;
    if (action.marker.key(n).comment == "e1") ease(time,tNext-mf,tNext,100,0)

    }catch (err){
    0;
    }
    }

    I thought it would have been in the tNext = action.marker.key(n+1).time; – but that doesn’t seem to do what I’m looking for! Any help would be greatly appreciated!

    David Conklin replied 11 years, 5 months ago 2 Members · 3 Replies
  • 3 Replies
  • David Conklin

    December 1, 2014 at 11:54 pm

    It is hard to say without knowing what exactly you mean by ‘a few’ keyframes and which marker you’d like to skip. Perhaps some more info could be helpful in determining a solution for you.

    That being said, it seems that what you’re looking for is highly case-specific. Perhaps instead of trying to code everything using one set of markers/keys, you can make another layer called ‘transition_markers’ with only the markers relevant to your fades or something and point your expression to that layer.

    Give some more info and I’ll do my best to help you. 🙂

    David Conklin
    Motion Designer

  • Dave Gorrie

    December 2, 2014 at 1:02 am

    Ah dang….sorry, I think I explained that a little wrong!

    So, currently the script finds the next marker and fades in/out if I have a slider above “0” – what I’d like it to do is actually find the 2nd marker down the timeline (so not the next one, but the one after that) to have the fade in/out action.

    Does that make more sense? Sorry, I just threw the word keyframes there and made my question waaaaayyy more confusing!

    Thanks for taking a look at it!

  • David Conklin

    December 2, 2014 at 6:07 pm

    The expression attached below will give you the time of the 2nd marker ahead of your playhead.

    var action = thisComp.layer(1);

    //get the time of the closest key.
    var theKey = action.marker.nearestKey(time);

    //determine if nearest key is before or after
    //the current time
    var lookAhead;

    if(theKey.time <= time){
    //key is before, get 2 markers past this one.
    lookAhead = Math.min(theKey.index + 2, action.marker.numKeys);
    } else {
    //next key is ahead, get one marker past this one.
    lookAhead = Math.min(theKey.index + 1, action.marker.numKeys);
    }

    //get time of 2 keys ahead.
    var twoKeysAheadTime = action.marker.key(lookAhead).time;

    twoKeysAheadTime;

    However, this will not be useful to you in constructing a fade as the way the linear() function works cannot create values in the future. Take this as an example:

    linear(time, nextMarker.time, twoMarkersahead.time, 0, 100);

    This expression won’t do anything as your playhead (i.e. the value of time) can, by definition, never be between the next marker and 2 markers ahead, it will either be 1) before all markers, 2) between the previous and next marker, or 3) past all markers.

    So, let’s discuss other ways of doing this. If you know that you want your fade to happen between the last 2 markers on your layer, you could do something like:

    linear(time, marker.key(marker.numKeys-1).time, marker.key(marker.numKeys).time, 0, 100);

    You can change the numbers to move back to the third-to-last and second-to-last keyframes as such:

    linear(time, marker.key(marker.numKeys – 2).time, marker.key(marker.numKeys – 1).time, 0, 100);

    Hopefully that points you in the right direction. If you have more info about what, exactly, it is you’re trying to do I may be able to give you some case-specific advice.

    Good luck!

    David Conklin
    Motion Designer

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