Skip to main content
Paul Cristo
Inspiring
October 5, 2023
Question

Expression to determine each value of next 100 frames

  • October 5, 2023
  • 3 replies
  • 2775 views

I'm trying to write an expression that gets the value of a property for each of the next 100 frames and determine if they're all below a certain value. If they are, change a boolean to true and vice versa. Is this possible in the After Effects paradigm? Thanks. 

This topic has been closed for replies.

3 replies

Dan Ebberts
Community Expert
October 5, 2023

Something like this, probably (this example is for the layer's rotation property):

prop = rotation;
threshold = 20;
val = true;
for (i = 0; i < 100; i++){
  if (prop.valueAtTime(time + framesToTime(i)) >= threshold){
    val = false;
    break;
  }
}
val

 

Community Expert
October 5, 2023

Dan, how would you use a property in an array like Scale or Position? When I try position[0] instead of rotation I get an error. The only way to not break the expression is to create an array for threshold, but I only want to look at the Y position. 

 

Paul, you have to add an argument that does something when the val changes from true to false. Something like this;

You'll then need to work out a time when the "val" changes from true to false and use that to drive an interpolation method like ease(tome, time of the change, time of the change + duration, start value, end value).

 

Dan, you can see the problem in the threshold line of the expression. I only want to look at the Y value.

 

 

ref = thisComp.layer(index + 1);
prop = ref.position;
threshold = [700, 540];
val = true;
for (i = 0; i &lt; 100; i++){
  if (prop.valueAtTime(time + framesToTime(i)) &gt;= threshold){
    val = false;
    break;
  }
}
val

if (val == true){
	a = "Do Something"
}
else{
	a = "Do something else"
}

 

 

 

Roland Kahlenberg
Brainiac
October 6, 2023

The keyframes you're talking about are the audio-converted-to-keyframes, is that correct? I think the expression looking at those has to make some decisions, based on the duration of any silent or sound patches, compared to what's happened recently and what's coming up. I don't see any way around that, but I may be missing something obvious (wouldn't be the first time).


My thoughts are to capture something 100 frames ahead in time is the same as capturing at current time and then moving these keyframes back in time by 100 frames. 

Sense Make?

Very Advanced After Effects Training | Adaptive &amp; Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV
Community Expert
October 5, 2023

If you are trying to look forward from the current time to the next 100 frames, you are going to end up with a recursive expression that slows down the farther down the timeline you go. The slowdown can be exponential. You will have to take time and create a loop that looks forward 100 * thisComp.frameDuration and looks for your critical value. It can throw a switch or change a color if it finds it and returns a false value.

 

Add this expression to a text layer above a layer with an animated position property, and it will tell you whether the layer is above or below the center of the comp 100 frames ahead of the current time.

 

lookForward = 100 * thisComp.frameDuration;
v = thisComp.layer(index + 1).transform.position.valueAtTime(time + lookForward);
trgtVal = thisComp.height/2;
if (v[1] < trgtVal){
	p = ": Top"
}
else{
	p = ": Bottom"
}
"Position" + p

 

It won't compare all 100 frames, but it would look ahead to detect the change.

 

If I get some free time later on, I will take a look at adding a loop operator to check if any frame is above the target value.

Mylenium
Brainiac
October 5, 2023

Sure. A simple for() loop will do.

 

Mylenium