Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How can I trigger ease or linear expression with an if-else statement? (and one more question)

Contributor ,
Feb 12, 2021 Feb 12, 2021

Hello everyone. 

What I am trying to do is creating a little script to automate a process. I have an if-else statement like this

if(value=keyframe1.value) -> 0
else -> 5

What I am trying to do is instead of instantly goes from 0 to 5 or the opposite, I want it to change slowly. But how can I change in or out points according to the if-else results? Maybe I need to use something other than ease/ linear? 

And one more question. 

Is it possible to get the value of a keyframe's first position when it added? I know most likely this is not possible but wanted to ask anyway. 

TOPICS
Expressions , Scripting
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Feb 17, 2021 Feb 17, 2021

For a smooth transistion, you need linear() or ease() function.

 

The key to both is a useable time-value and there are several ways to get one - however, we need more details for a better answer.

 

You can read-out a given time-point (a marker, a keyframe, in- or out-point of a layer) and use this as trigger.

For example:

tstart = key(1).time

tend = tstart + 0.5 // half a second

linear(time, tstart, tend, value1, value2)

 

Trigger is the time position of the first keyframe.

 

You can read out the time-poin

...
Translate
LEGEND ,
Feb 12, 2021 Feb 12, 2021

It's all possible, but much more complicated. You have to use valueAtTime() and retrieve the values in a loop and then use the ease() function as a filter on the output.

 

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 12, 2021 Feb 12, 2021

Hey Mylenium, 

Thank you for the answer, but the thing I am stuck at is how to trigger ease part. 

For example this is what I tried to do (... is a puppet pin position, it is too long so I just put ...)

...("Position").nearestKey(time).value=...("Position").key(1).value)
{
t=...("Position").nearestKey(time).time;
linear(time,t,t+.3,valueAtTime(0),valueAtTime(1));
}


Looks like that triggers linear, but when it comes near to the second keyframe result becomes 0 again. I am stuck 😕  

One more problem is, I have no idea how to make it go from 7 to 0 as well. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 12, 2021 Feb 12, 2021

Looks like I forgot to add if( at the start of the code. It doesn't let me edit it for some reason so I am writing another reply instead. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 17, 2021 Feb 17, 2021

It's difficult to see exactly what you want to achieve — can you post the entire Expression you are currently using and what it is that you want to achieve?

Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 17, 2021 Feb 17, 2021

Hey, this is my expression. 

if(thisLayer.effect("ADBE LIQUIFY")("Distortion Mesh").key(1).value==thisLayer.effect("ADBE LIQUIFY")("Distortion Mesh").value) 
{ 
0; 
}else{ 
5; 
}

 

Currently, it switches from 0 to 5 (and opposite) instantly. What I want to do is make it switch slowly. 0 to 5 in half second for example. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Feb 17, 2021 Feb 17, 2021

For a smooth transistion, you need linear() or ease() function.

 

The key to both is a useable time-value and there are several ways to get one - however, we need more details for a better answer.

 

You can read-out a given time-point (a marker, a keyframe, in- or out-point of a layer) and use this as trigger.

For example:

tstart = key(1).time

tend = tstart + 0.5 // half a second

linear(time, tstart, tend, value1, value2)

 

Trigger is the time position of the first keyframe.

 

You can read out the time-point dynamically. There are several ways from iterating through all keyframes and find the fitting one (fitting is defined by your own conditions), or use the built-in function nearestKey() (which will switch to the next key automatically, when this key is closer to the CTI than the previous one - this behaviour can be unwanted, for example, if keyframes are close together an the transistion isn't finished yet).

 

You can also make this completly autopilot. You can iterate through all frames (starting from 0 and going forward, as well as starting from current time and going backward/forward) and check a value of your choice at this time-point againt the trigger-value.

 

for (i = 0, i <= time, i+oneFrameInSeconds){

if (someLayer.opacity == 45){

tstart = i

tend = tstart + 0.5

linear(...)

break

 

However, such an expression is a heavy loader (I use to call this the Doom-Loop), because it iterates all frames for every frame. The longer your comp is (the later your trigger value appears), the more iterations necassary and the slower everything will be.

 

*Martin

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 19, 2021 Feb 19, 2021

I will definitely try this but I am too busy for the next few days, thanks for the answer 🙂 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 24, 2023 Mar 24, 2023

Hey Mugen,

Did you solve the problem.

I'm trying to tackle this myself but I can't find a solution.

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 27, 2023 Mar 27, 2023
LATEST

Sorry but I don't remember at all, it's been years. I don't even remember why I asked in the first place 😕

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines