Activity › Forums › Adobe After Effects Expressions › Markers and expressions
-
Markers and expressions
Posted by Øyvind Veberg on January 24, 2006 at 8:53 pmHi!
Anybody who know if there is a way to make AE “do something” (e.g. trigger a series of keyframes) whenever it hits a marker on a layer? I’ve been looking at Dan Ebberts “Synchronizing Animation to Audio” tutorial here on the Cow. It is close to what I’m looking for, but I ‘m having trouble figuring out how to make it work if it’s not connected to time remapping.
Is there a way to write an expression that will make “hit=marker.key(1).time” valid for every marker on a layer (not just the first one)?
Cheers!
Øyvind Veberg replied 20 years, 3 months ago 3 Members · 4 Replies -
4 Replies
-
Dan Ebberts
January 24, 2006 at 10:29 pmThis assumes that your keyframed action occurs starting at time = 0. The animation will trigger at each marker:
n = 0; if (marker.numKeys > 0){ n = marker.nearestKey(time).index; if (marker.key(n).time > time){ n--; } } if (n > 0) t = time - marker.key(n).time else t =0; valueAtTime(t);Dan
-
Colin Braley
January 24, 2006 at 11:13 pmI think I’ve got what you are looking for but I am not quite sure. You are saying you want an expression that works such that: if your current time is past a certain marker use the animation keyframed in for a layer, if not just keep the value static. I made a quick example using scale. Feel free to modify the variables called: beginVal, nk, and targetMarker. The expression I wrote will set the scale parameter equal to beginVal unless the time is past the targetMarker. You also must set nk equal to the number of markers on your layer prior to use. There might be a way to get the number of markers on a layer using some code but I’m not sure. Well anyway enough of my ramblings here’s the expression for scale:
beginVal = [50, 50];//Value of parameter before you have hit the desired marker
nk = 3;//Change this to the number of markers on your layer
targetMarker = 2;//After the comp’s time is greater than this target marker the
//animation of this parameter will be controlled by keyframes//———-
//Modify below this line at your own risk 🙂
//———-hit = new Array( nk );
for(i = 1; i <= nk; i++) hit[i] = marker.key(i).time; //-- if(time > hit[targetMarker])
{
if(numKeys == 0)
beginVal
else{
timeBegin = marker.key(1).time;
diff = Math.abs( time – hit[targetMarker ]);
this.valueAtTime( timeBegin + diff)
}
}else{
beginVal
}
//End expression~Colin
By the way, I haven’t tested this expression for strange conditions such as a layer that has no keyframes or no markers, so under these situations it may not work
-
Colin Braley
January 24, 2006 at 11:17 pmI didn’t see that you already posted an answer while I was coding mine Dan 🙂 Well anyway heres a way to do it without the whole nk thing:
beginVal = [50, 50];//Value of parameter before you have hit the desired marker
targetMarker = 2;//After the comp’s time is greater than this target marker the
//animation of this parameter will be controlled by keyframes//———-
//Do not modify below this line
//———-hit = new Array( marker.numKeys );
for(i = 1; i <= marker.numKeys ; i++) hit[i] = marker.key(i).time; //-- if(time > hit[targetMarker])
{
if(numKeys == 0)
beginVal
else{
timeBegin = marker.key(1).time;
diff = Math.abs( time – hit[targetMarker ]);
this.valueAtTime( timeBegin + diff)
}
}else{
beginVal
}
//End expression -
Øyvind Veberg
January 25, 2006 at 12:39 amMan, you guys are fast AND smart!
It’s late at night here in Norway, so my brain isn’t quite in javascript mode at the moment, but I will check it out tomorrow. It sure looks like what I was looking for.
Thanks a lot!
Cheers!
Reply to this Discussion! Login or Sign Up