ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How to freeze an expression at a specific time

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Francesco Bona
How to freeze an expression at a specific time
on Aug 21, 2018 at 1:31:20 pm

Hi I read some posts similar to this but I'm still a bit confused.
How can I freeze an expression at a specific time or frame to keep all properties it controls locked in the exact state they were at that specific moment?

I did a test with a simple "wiggle"expression applied to an object position but I did not get what I wanted.
At the specified time (frame number 100) I get the original object position as if it was not controlled by the wiggle expression.
What I wanted instead was to freeze the object position as it was at frame 100.
I don't want to simply desable the expression at frame 100, I want to freeze the expression at frame 100.
And I can't precompose

I used this expression:

w=wiggle(5,100);
stop = 50;
timecode=timeToFrames(time);
prestop=50;

if (timecode < stop){
w;
}else{
valueAtTime(prestop);
}


What did I do wrong?
Thanx!!!


Return to posts index

Dan Ebberts
Re: How to freeze an expression at a specific time
on Aug 21, 2018 at 3:35:56 pm

Try this:

stop = 50;
t = Math.min(time,framesToTime(stop));
wiggle(5,100,1,.5,t)


Dan



Return to posts index

Francesco Bona
Re: How to freeze an expression at a specific time
on Aug 21, 2018 at 4:28:01 pm

Wow!! Much more synthetic and functional! Thanks so much!
But now I undertand I need to do one more question.. I'm sorry ..I used "wiggle" as an easy expression example hoping to adapt your suggestions to my real and bigger problem.
My real intent was to understand how to freeze at a specific time any expression..

This is my real mission: freezing at a specific time this expression that keeps a shape linked to the bottom margin of another shape even if its scale is changing...

a=thisComp.layer("01"); // Key object
d=30; // Distance
s=a.transform.scale[1];
apos=a.transform.position[1];
ah=a.sourceRectAtTime(time).height/2;
s1=transform.scale[1];
h=thisLayer.sourceRectAtTime(time).height/2;

[180 , apos+(ah*s/100)+(h*s1/100)+d]


How can I freeze this expression for example at frame 50? I don't understand how to use "Math.min"
Thanks again.....


Return to posts index


Dan Ebberts
Re: How to freeze an expression at a specific time
on Aug 21, 2018 at 4:48:29 pm

Maybe like this:

stop = 50;
t = Math.min(time,framesToTime(stop));
a=thisComp.layer("01"); // Key object
d=30; // Distance
s=a.transform.scale.valueAtTime(t)[1];
apos=a.transform.position.valueAtTime(t)[1];
ah=a.sourceRectAtTime(t).height/2;
s1=transform.scale.valueAtTime(t)[1];
h=thisLayer.sourceRectAtTime(t).height/2;

[180 , apos+(ah*s/100)+(h*s1/100)+d]


Dan



Return to posts index

Francesco Bona
Re: How to freeze an expression at a specific time
on Aug 21, 2018 at 11:08:02 pm

I'm sorry but It doesn't seem to work ...
The expression continues to operate even after frame 50 and keeps the second object anchored to the bottom of the first.
What I need instead is the second object to remains frozen in the position it has at frame 50 even if the first object continues to move.


Return to posts index

Dan Ebberts
Re: How to freeze an expression at a specific time
on Aug 21, 2018 at 11:15:25 pm

Is there any parenting involved?



Return to posts index


Francesco Bona
Re: How to freeze an expression at a specific time
on Aug 22, 2018 at 5:45:59 am

No, only the expression


Return to posts index

Dan Ebberts
Re: How to freeze an expression at a specific time
on Aug 22, 2018 at 6:49:42 am

It works for me (freezes at frame 50). Clearly I must have things set up differently than you do.

Dan



Return to posts index

Francesco Bona
Re: How to freeze an expression at a specific time
on Aug 22, 2018 at 7:32:04 am

Ah ok but how can I have setup something different from you? The code is the same
In general which are the possible codes that block or freeze an expression?


Return to posts index


Francesco Bona
Re: How to freeze an expression at a specific time
on Aug 22, 2018 at 8:28:26 am

WAIT WAIT!!!! YOUR EXPRESSION WORKS!!! I WAS WRONG!
What made me think that it did not work is the "scale" of the second object.
It scale as its "anchor point" was still linked to the bottom margin of the first object.

I'm understanding.. It's my fault, I'm explaining very badly.
I need the second object to stop in that moment. But I also need, from that moment on, to be free to modify its property without being conditioned by the expression.

The meaning is:
- Before frame 50 the second object remains linked to the bottom edge of the first object
- At frame 50 it stops with the exact dimension and position it has at that moment and if I do nothing it remains as it is and no longer follows the first object.
- After frame 50, If I change its parameters, such as position and scale, I must be free to do so without being bound by the expression that acted before. So from this moment I need it to behave as if it were created with these characteristics and position
Is this clearer? Sorry but as you can see my english depends on google and it's really difficult for me to explain these things.


Return to posts index

Francesco Bona
Re: How to freeze an expression at a specific time
on Aug 22, 2018 at 9:34:30 am

I add only one thing to clarify:
Perhaps my biggest mistake was to talk about "freezing" because this makes think of an object that from a certain moment on remains blocked as it is. I need it stops as it is not to be blocked forever with the properties it has in that moment.

It is better to say that I'm looking a way to stop an expression to operate at a specific time, leaving the object as it is at that specific moment and free from its control.

The problem with last expression infact is that the object, from frame 50 on, seems to keep its properties forever linked to the conditionings it had in that frame. So what I get is not an object that I can control freely.
- position is locked as it was at frame 50
- scale anchor point is locked as it was at frame 50
So expression is not "off" as I need from frame 50 to on. Expreesion is frozen at frame 50.
I really need to find a way to make the expression stops to work after frame 50 but at the same time I need the object not simply to return as if it was without its control.

I need the object to stops as it was at last frame the expression was active but without being conditioned by it from then on.


Return to posts index

Kalleheikki Kannisto
Re: How to freeze an expression at a specific time
on Aug 22, 2018 at 11:16:47 am

Add a "value +" at the beginning of the last line of the expression. In that way the manual value of the property is added to the expression, frozen or not. (You may need to change the original value of the property for this to work as expected.)

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index


Francesco Bona
Re: How to freeze an expression at a specific time
on Aug 22, 2018 at 12:15:12 pm

Thanks but I can't reposition the object manualy. The expression is made specifically to link the second object to the bottom margin of the first object. And the firts object is wiggled or moved by other expressions. So as I said it is impossible to manually reset the position to the right place.

If you want to test or study my specific situation you need just to:

- create 2 shapes
- put a "heavy" wiggle expression to position and scale of the first object
- put this expression to the position of the second object
stop = 250;
t = Math.min(time,framesToTime(stop));
a=thisComp.layer("01"); // Key object
d=30; // Distance
s=a.transform.scale.valueAtTime(t)[1];
apos=a.transform.position.valueAtTime(t)[1];
ah=a.sourceRectAtTime(t).height/2;
s1=transform.scale.valueAtTime(t)[1];
h=thisLayer.sourceRectAtTime(t).height/2;

[value[0] , apos+(ah*s/100)+(h*s1/100)+d]


As you can see at frame 250 the second object stops exactly in the position it was at that frame - and this is ok - but now you can't move the y position anymore cause it's locked. And if you change the scale it changes as if its upper margin and position where locked.

So... the problem remains the same: to obtain an object that, after frame 250 is unlinked from the expression, still in the exact position that it had under the control of the expression at frame 50, but free to be moved.

I understand this case this case is becoming a mess and it's my fault.. But seriously, I did not imagine it could be such a complicated thing..
I really don't know how to solve this problem


Return to posts index

Francesco Bona
Re: How to freeze an expression at a specific time
on Aug 22, 2018 at 1:29:31 pm

Now that I'm really late I'll proceed with a workaround that I'd rather not use: baking the second object position and keeping just the keyframe at frame 250 that is my stop. The result is exacty what I was trying to get directly into the expression but it makes my composition very chaotic. Infact here I'm talking about 2 objects but in reality I'm workin on more than 20 layers.
In any case, I would like very much to find out how to solve with an expression.


Return to posts index

Francesco Bona
Re: How to freeze an expression at a specific time
on Aug 24, 2018 at 9:11:06 am

Hi guys, could you just tell me if there's not a solution because of my chaotic explanation or just because this operation must be done without expressions? I'm sorry but I'm really in trouble. I don't want to bother you, I'm just trying to find - at least - a path to the solution.

Thank you


Return to posts index


Kalleheikki Kannisto
Re: How to freeze an expression at a specific time
on Aug 24, 2018 at 10:02:47 am

You can use value-valueAtTime(0)+[value[0] , apos+(ah*s/100)+(h*s1/100)+d] as your last line. That way the original position value will not affect the position and it ends up being exactly in the same place -- as long as you don't move the 2nd object during those first 250 frames.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

Francesco Bona
Re: How to freeze an expression at a specific time
on Aug 24, 2018 at 11:52:37 pm

I really thank you but it's clear that I'm not getting through.
The expression still doesn't allow me after frame 250 to move the object on the y axis and as I said the scale property still fells the restriction of the bottom margin of the firt object.

I definitely need a simpler case to understand each other so forget my "bottom margin link" expression. Really. I think the best possible example which sums up my needs is "unparent a child layer from the parent at a specific time".

Yes my needs are substantially similar to a "layers parenting" because when a layer is parented to another it follows its movements and changes but - this is the thing - if you unparent the child from the parent, the child keeps is own actual state.
It doesen't return to its native state and even if it's free to be moved or changed its new "0 state" or "native state" has become that in which the last parenting instant has left it.

This is exacty what I'm tryng to acheave. I have a more complicated situation than this but the gist is the same so I repeat: forget about my previus expression. What I'm asking to you all is this:
How can I write an expression to unparent a child layer from its parent - for example - at frame 250?
Once again, thank you all for your patience..


Return to posts index

Kalleheikki Kannisto
Re: How to freeze an expression at a specific time
on Aug 25, 2018 at 11:06:00 am

The usual way to handle the unparenting is to split the child layer at that point and then unparent the copy while the current time indicator is at the split point, which retains the child transformations at that point in time.

The expression method is to allow the manual value to be added to the expression value and then disable the expression at a given time. This means you can't have keyframed changed before the "release" time.

To me it seems like your question has been answered but your project is probably more complicated than the situation you're describing if you're not getting the expected result. Can you upload a project file that just has two layers with all the expressions and keyframes you currently have? Then we could see what the problem that you're encountering really is.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index


Francesco Bona
Re: How to freeze an expression at a specific time
on Sep 2, 2018 at 5:19:38 pm

I'm sorry I waited so long to answer but I wanted to study deeply your suggestions. Finally I understood that I was wrong and you were right! I thought the expression did not work because I was trying to move layer "B" with my mouse and not with keyframes! With keyframes everything works perfectly !!
So.. Thank you all again. Thanks to you I'm making huge steps forward ... Regarding my project: I have uploaded a very simplified scene of my current situation.
12685_creativecow01.aep.zip
As you will notice the expression applied to the second object is now a bit different - but congruent to your suggestions - because I wanted to be able to change the anchor points without changing the result.
I also wanted to use a marker as a stop frame.

D=30;
Stop = thisLayer.marker.key(1).time;
Duration=Math.min(time,Stop);
A=thisComp.layer("A");
AS=A.transform.scale.valueAtTime(Duration)[1];
AY=A.transform.position.valueAtTime(Duration)[1];
AH=A.sourceRectAtTime(Duration).height/2;

AAncorY=thisComp.layer("A").transform.anchorPoint[1];
ThisAncorY=transform.anchorPoint[1];

ThisS=transform.scale.valueAtTime(Duration)[1];
ThisH=thisLayer.sourceRectAtTime(Duration).height/2;

value-valueAtTime(0)+[value[0] , AY+((AH-AAncorY)*AS/100)+((ThisH+ThisAncorY)*ThisS/100)+D]


Thanks again!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]