Activity › Forums › Adobe After Effects Expressions › expression for key frame detection?
-
expression for key frame detection?
Posted by Kevin Camp on June 11, 2007 at 6:05 pmi’m trying to create an expression that will be generating position changes automaticly, but if there were already key frames for postion, then i wanted the new postion to be based on that key frame data, if there was no key frame then new postion would be based on original postion.
is there a way for an expression to detect if there is a key frame?
i have created a check box control, to manually choose to use key framed data, but i was hoping to make the process a little more mindless.
Kevin Camp
Designer – KCPQ, KMYQ & KRCWLing Talfi replied 13 years, 11 months ago 4 Members · 8 Replies -
8 Replies
-
Lord Scales
June 11, 2007 at 7:15 pmI would not detect the keyframes, but the speed. If the speed is higher than 0, or there is an expression or keyframes. Like this:
thisComp.layer (“Layer 1”).position.speed
But supposing you’ve got the floowing:
thisComp.layer (index – 1).position
You can just do this:
value + thisComp.layer (index – 1).position
VALUE is the original value with no expression. So you can play around.
-
Kevin Camp
June 11, 2007 at 8:00 pmthanks, i’ll see what i can do with this.
Kevin Camp
Designer – KCPQ, KMYQ & KRCW -
Kevin Camp
June 11, 2007 at 8:56 pmthere seems to be a problem using speed… it works great, except when the keyframes are not at the beginning and end of the comp, then it calculates new position data until it detects speed (the first keyframe) where it jumps the the keyframed postion, then works great. then similar but reverse effect happens when the last keyframe is before the end of the comp, where it finished the move, but then jumps to the non-speed detected postion.
i am trying to get it to hold prior to the first keyframe and after the last, if the layer has movement (or keyframes), but create movement if it does not.
Kevin Camp
Designer – KCPQ, KMYQ & KRCW -
Filip Vandueren
June 11, 2007 at 9:25 pmHi Kevin,
what exactly are you trying to do ?
Does it wiggle, but only when moving, or is it spinning circles around itself, but only when there are keyframes etc.
What’s the movement or the expression you’re applying to your layer ?
Perhaps there’s a simpler solution to this.
-
Kevin Camp
June 12, 2007 at 6:09 pmi figured out a way to do it using if(numKey > 0)….
what i was trying to do was simplify and expression that started to get pretty complicated with unnecessary controls that had been adding based on feedback from some people who tried it.
it started as a fairly simple expression to create y movement for a list of credits that would not flicker due to field interference using a process outlined by dave laronde here a few months ago. i had just started looking into what expressions could do beyond randomness and linking attributes, and i thought this would be a fun exercise, and i came up with this:
startY = thisComp.height + (thisLayer.height / 2); // Start position based on layer Y height;
endY = (thisLayer.height / 2) * -1; // End postion based on credit length (height)
frameRate = 1 / thisComp.frameDuration;
duration = frameRate * thisComp.duration;
displace = startY – endY;
frameNum = frameRate * time;
Yinc = (Math.round(((displace / duration) / 2) + 0.5)) * 2; // make movement field friendly (mult of 2)y = startY – (Yinc * frameNum);
[value[0],y]
then after some feedback, i added controls for field friendly movement or anti-alias friendly movement, adding sliders to add padding to the front and end, adding control for placement at the front…. but it seemed that it should be easier to use, and most people, if the needed to, would just want to add a keyframe where they wanted to have the credit roll start and end rather than deal with sliders.
so this is what i came up with so far… (it works, but it may still need some refinement.. this is my first real expression)
n = numKeys;
if (n > 0){
if (n == 1){ // If only one key, determine if it is start or end key
if (key(1).time < thisComp.duration / 2){ // If key is in the first half of comp, assume start key startY = key(1).value[1]; // Start postion based on Y position from keyframe startT = key(1).time; // Start time based on first keyframe endY = (thisLayer.height / 2) * -1; // End postion based on credit length (height) endT = thisComp.duration; }else{ // If key is in last half of comp, assume end key startY = thisComp.height + (thisLayer.height / 2); // Start position based on layer Y height; startT = 0; endY = key(1).value[1]; // End postion based on Y position from keyframe endT = key(1).time; // End time based on keyframe } }else{ startY = key(1).value[1]; // Start postion based on Y position from first key startT = key(1).time; // Start time based on first key endY = key(n).value[1]; // End postion based on Y position from last key endT = key(n).time; // End time based on last key } }else{ startY = thisComp.height + (thisLayer.height / 2); // Start position based on layer Y height; startT = 0; endY = (thisLayer.height / 2) * -1; // End postion based on credit length (height) endT = thisComp.duration; } frameRate = 1 / thisComp.frameDuration; duration = frameRate * (endT - startT); // Duration (frames) between keyframes displace = startY - endY; frameNum = (frameRate * (time - startT)); if (frameNum < 0){ // If uing keyframes, there is no movement until the first key frameNum = 0; }else{ frameNum; } // Allow Y movement to be calulated as field friendly (multiple of 2) or just anti-alias friendly if (effect("Field Friendly Movement")("Checkbox") == true){ Yinc = (Math.round(((displace / duration) / 2) + 0.5)) * 2; }else{ Yinc = Math.round((displace / duration) + 0.5); } yPos = startY - (Yinc * frameNum); if (yPos < endY){ // If using keyframes, take final postion from end key y = endY; }else{ y = yPos; } [value[0],y] Kevin Camp Designer – KCPQ, KMYQ & KRCW -
Kevin Camp
June 13, 2007 at 9:57 pmi like your speed detection… i can think of some good uses for that.
Kevin Camp
Designer – KCPQ, KMYQ & KRCW -
Ling Talfi
May 14, 2012 at 8:05 amif( time < transform.position.key(2).time ){
wiggle(2.5, 3);
}
else{
value
}
Reply to this Discussion! Login or Sign Up