ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

start/stop expression at specific time

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
atomicrabbit
start/stop expression at specific time
on Jul 27, 2007 at 7:12:14 pm

Is there a way to start/stop an expression at a specific time. I've tried using a checkbox with if statement to start it at a specific frame and it worked fine, but when I turn it off to stop the expression, it does not stay at the position the expression moved it to. It reverts to the size/position it was before the expression.

How can I get around this problem.


Return to posts index

yikesmikes
Re: start/stop expression at specific time
on Jul 27, 2007 at 7:25:30 pm

ok, somebody will have a more sophisticated solution, but to keep that expression value (Position) you can always split the layer (Edit>Split Layer) then on that upper layer set a Position keyframe (or whatever property the expression is on), then disable the expression (click the equal sign next to the stopwatch). You should be good to go.


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Jul 27, 2007 at 8:04:00 pm

What's the code for your expression?

Dan


Return to posts index


atomicrabbit
Re: start/stop expression at specific time
on Jul 27, 2007 at 8:08:26 pm

[Dan Ebberts] "What's the code for your expression?

Dan"


I found this code from a post. It's to make a falling leaf effect, but I modified the code a little. I'm also using a checkbox to start the expression.

position
-----------------------------------------------------------------------------------
control = effect("Checkbox Control")("Checkbox") ;
whattime=time-3;
if (control == 1){
sp=2;
amp=150;
gravity = 50;
x = Math.sin(whattime*sp)*amp;
y = Math.sin(whattime*1.5)*50;
value + [x,y];
}else{
value;
}



scale
------------
control = effect("Checkbox Control")("Checkbox") ;
whattime=time-3;
if (control == 1 || value > 40){
gravity = 50;
z= whattime*whattime
value - [z,z];
}else{
value;
}



rotation
------------------------------------------------------------------------------------
control = effect("Checkbox Control")("Checkbox") ;
whattime=time-3;
if (control == 1){
sp=2;
amp=5;
x = Math.sin(whattime*sp)*amp;
value - x;
}else{
value;
}


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Jul 27, 2007 at 8:38:40 pm

Give this a try (for position):

chkBx = effect("Checkbox Control")("Checkbox");

n = 0;
if (chkBx.numKeys > 0){
n = chkBx.nearestKey(time).index;
if (chkBx.key(n).time > time){
n--;
}
}

t = 0;
curTime = time;

if (n > 0){
for (i = n; i > 0; i--){
if (chkBx.key(i).value > 0){
t += (curTime - chkBx.key(i).time);
}
curTime = chkBx.key(i).time;
}
if ((curTime > 0) && (chkBx.key(1).value > 0)) t += curTime;
}else{
if (chkBx.value > 0) t = time;
}

sp=2;
amp=150;
gravity = 50;
x = Math.sin(t*sp)*amp;
y = Math.sin(t*1.5)*50;
value + [x,y];


Dan


Return to posts index

George Costakis
Re: start/stop expression at specific time
on Apr 4, 2009 at 11:43:06 pm

I doubt anyone will see this, but what about for this expression?

veloc = 7;
amplitude = 80;
decay = .7;

amplitude*Math.sin(veloc*time)/Math.exp(decay*time)

right now it starts at the beginning of the comp even if i try the split and duplicate layer trick. any help would be great.
-george


Return to posts index


Brennan Shappell
Re: start/stop expression at specific time
on Aug 25, 2010 at 4:25:14 pm

I also am trying to get the decaying pendulum expression to start at a time specified(not the beginning of the comp).
Thanks for any help!

veloc = 5;
amplitude = 20;
decay = .9;

amplitude*Math.sin(veloc*time)/Math.exp(decay*time)


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Aug 25, 2010 at 5:31:20 pm

This is one way:


beginTime = 4; // start at 4 seconds
if (time < beginTime){
0
}else{
t = time - beginTime;
veloc = 5;
amplitude = 20;
decay = .9;
amplitude*Math.sin(veloc*t)/Math.exp(decay*t)
}


Dan



Return to posts index

Brennan Shappell
Re: start/stop expression at specific time
on Aug 25, 2010 at 5:36:17 pm

Thanks for the absurdly fast turn around time on that, Dan =]
Works like a charm.


Return to posts index


Maurito Zarate
Re: start/stop expression at specific time
on Oct 27, 2011 at 7:56:30 pm

Hallo Dan, I didn't understand in this your code where is the END parameter where the expression stops. I Understood that at 4 second starts expression (beginTime = 4;)
BUT where stops???
For instance, in your expression (), if the comp is 10 seconds and I'd like to activate expression from 2 second to 8 second, what I have to write?

beginTime = 4; // start at 4 seconds
if (time < beginTime){ 0 }
else{ t = time - beginTime;
veloc = 5; amplitude = 20; decay = .9; amplitude*Math.sin(veloc*t)/Math.exp(decay*t) }

THX!


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Oct 27, 2011 at 8:21:01 pm

It doesn't actually stop. Eventually it settles out to approximately zero, but the timing depends on the decay variable. If you wanted it to just stop at whatever value corresponds to 8 seconds, you could do this:


beginTime = 4; // start at 4 seconds
endTime = 8;
if (time < beginTime){
0
}else{
t = Math.min(time,endTime) - beginTime;
veloc = 5;
amplitude = 20;
decay = .9;
amplitude*Math.sin(veloc*t)/Math.exp(decay*t)
}



Dan



Return to posts index

Maurito Zarate
Re: start/stop expression at specific time
on Oct 28, 2011 at 7:05:46 am

Thx Dan,
my problems with expression is almost alway the same Start and End it at a determinate time...
Regardless of the content of the expression, I would like to understand what commands to use to start a particular second and make it cease to another second...
For example, i have this expression applied ti Light parameter:

probability = 6;
opacity_normal = 100;
x = random(probability);
if (x <= 1) {
opacity = random(100);
} else {
opacity = opacity_normal;
}

I'd like to apply to this expression a Start time (at 36th second) and a n End time (at 39th second). Can I utilize your command? Something like this...:


beginTime = 36;
endTime = 39;
probability = 6;
opacity_normal = 100;
x = random(probability);
if (x <= 1) {
opacity = random(100);
} else {
opacity = opacity_normal;
}

?????

THX!


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Oct 28, 2011 at 7:36:48 am

It would be more like this:


beginTime = 36;
endTime = 39;
probability = 6;
opacity_normal = 100;
if (time >= beginTime && time < endTime){
x = random(probability);
if (x <= 1) {
random(100);
} else {
opacity_normal;
}
}else{
opacity_normal;
}



Dan



Return to posts index

Maurito Zarate
Re: start/stop expression at specific time
on Oct 28, 2011 at 7:57:48 am

Great Dan!

THX!


Return to posts index

Sefik Soyer
Re: start/stop expression at specific time
on Jan 19, 2012 at 2:42:56 pm

Hi Dan,

It's my first time posting here on this forum, kind of excited and hope I can make it work :)

Apparently this subject (Start/Stop Expression at Specific Time) has been out here for a long time, and even though I think I thoroughly looked into it, somehow I couldn't make the code work for me :(

Basically, I wanted my expression to start at a certain frame but as I just mentioned I couldn't figure out what I'm doing wrong after I spent 3 hours and gave up at this point!

I have a composition with 12fps and I have my TEXT layer, which I applied the expression on 'the expressions code box' below to its POSITION parameter, hoping that it would move on x-axis, however it doesn't do anything at all!

But when I just use this code below:



freq = 15;
amplitude = 100;
decay = 3;

x = amplitude*Math.cos(freq*time*2*Math.PI)/Math.exp(decay*time);
position + [x,0];



Then it works but it starts moving at the beginning of my composition, not on the frame I want it to.

I tried everything that has been mentioned on this thread ( interestingly some scripts don't even work at all for me) and I did search on Adobe's forum as well, which I'll post there as well in a second :)

So what am I doing wrong ?

How am I going to make my expression work and move the TEXT layer as it is supposed to on that specific frame I would like to ?

Any kind of answer/help/explanation will be greatly appreciated :)

Have a great day!

cheers,


Sefik

beginTime = 40;
if (time > beginTime) {

freq = 15;
amplitude = 100;
decay = 3;

x = amplitude*Math.cos(freq*time*2*Math.PI)/Math.exp(decay*time);
position + [x,0];

} else {
0
}


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Jan 19, 2012 at 3:19:20 pm

Assuming you want it to start at frame 40, try it this way:


beginFrame = 40;

t = time - framesToTime(beginFrame);
if (t >= 0) {
freq = 15;
amplitude = 100;
decay = 3;
x = amplitude*Math.cos(freq*t*2*Math.PI)/Math.exp(decay*t);
value + [x,0];
}else
value



Dan



Return to posts index

Sefik Soyer
Re: start/stop expression at specific time
on Jan 19, 2012 at 3:28:15 pm

Dan,

You're the man as we already all know!

Thanks a lot :)

Now I can go to sleep finally and peacefully :))


Return to posts index

James Valpy
Re: start/stop expression at specific time
on May 10, 2020 at 11:58:14 pm

Hey Dan,

Thanks for sharing your work, really helpful for people like myself 😉

I am working on an expression and cannot get it to work properly, please could you help? I am trying to make an expression that is on a contrast parameter, the expression should flash the contrast to 100 periodically with a delay offset for each layer that I apply the expression to. Imagine the flashing leading lights on a runway...

I had to use thisLayer.name because I'm working in 3d and index is the wrong way round for how I have positioned my layers in space. Currently this expression makes the flash on the first intended instance but doesn't repeat.

Cheers!

beginFrame = (framesToTime(thisComp.layer("Controls").effect("Flash Delay")("Slider"), fps=.04/thisComp.frameDuration)*(Math.round(thisLayer.name)-1))+ thisComp.layer("Controls").effect("Flash Start")("Slider"); // start frame
t = time - framesToTime(beginFrame);
if (t >= 0) {
f = time - beginTime;
frequency=thisComp.layer("Controls").effect("Flash Frequency")("Slider"); // Hz
burstlength=2; // in frames

f=time%(1/frequency);

t &lt; framesToTime(burstlength) ? 100 : 0;;
}else
0


James Valpy
Black Dog Video


Return to posts index

david chasterfield
Re: start/stop expression at specific time
on Jan 14, 2015 at 7:31:50 am

hello my friend ;)
i been trying to pick whip the position of layer A with layer B at second 2... so far i tried a few simple expressions coz I'm new at expressions but i failed , nothing worked for me... here one of them :


timeToStart=2;
if (time >=timeToStart)
{
thisComp.layer("Shape Layer 1").transform.position
}


as you can see there in the middle all i do is pick whip the position of the layer A to layer B , trying to get it to follow starting from second 2 ...i tried this for the rotation and it did work , but for the position it gives me this error " expression result must be of dimension 2 , not 1. "...
so if u can help or maybe write me an example i can work with , that would be really great , thanks in advance


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Jan 14, 2015 at 7:48:08 am

The expression needs to provide a legal position value before the start time. I'm not sure if this does what you want, but it should avoid the error:

timeToStart=2;
if (time >=timeToStart)
{
thisComp.layer("Shape Layer 1").transform.position
}else{
value
}


Dan



Return to posts index

david chasterfield
Re: start/stop expression at specific time
on Jan 14, 2015 at 7:53:01 am

it did got rid of the error and it did what i wanted ^^
works like a charm ! thanks a lot my friend !


Return to posts index

david chasterfield
Re: start/stop expression at specific time
on Jan 14, 2015 at 8:25:58 am

actually I'm having another problem now , it didn't work with that shape layer because of the anchor point , so i used a null object and parented it to that shape layer and then used its position for the expression , but when second 2 comes the layer A the one i parented its position to the null's , it don't really follow it , it goes in some random position and it don't even move lol , thought its parented !


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Jan 14, 2015 at 8:31:27 am

The new expression will probably need to look like this:

timeToStart=2;
if (time >=timeToStart)
{
thisComp.layer("Null 1").toComp([0,0,0])
}else{
value
}


Dan



Return to posts index

david chasterfield
Re: start/stop expression at specific time
on Jan 14, 2015 at 8:45:50 am

ohh ok ok , yeah its moving with it now , and the layer don't really follow the anchor point of the null its following its top right corner ! but with a little adjustment made it perfect , and thanks to you of course , I've been searching the net for that for a quite a time now , couldn't find it or maybe didn't google the right words , but hey you the man ! thanks for your time and for making it work for me !! keep up ;)


Return to posts index

Ziggy Ziegelmueller
Re: start/stop expression at specific time
on Mar 6, 2014 at 1:01:12 am

SO, I am a bit of a noob at after effects, but I am having the same problem: not being able to start/stop expressions at the desired time. After finding this thread, I figured i would give it an ask. I will use the common "wiggle" expression as an expression template. Thi sis waht I have tagged to Position on a null object that is parented to a camera:
beginTime = 4; // start at 4 seconds
endTime = 8;
if (time < beginTime <endTime){
0
} else {wiggle(2,10)}

It returns this error (I have tried with the N.O. as a 3d layer as well as a 2d one).

"expression result must be of dimension 2, not 1"
Any ideas?


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Mar 6, 2014 at 1:10:04 am

I'd say try it this way:


beginTime = 4; // start at 4 seconds
endTime = 8;
if (time > beginTime && time < endTime)
wiggle(2,10)
else
value



Dan



Return to posts index

Cameron Walser
Re: start/stop expression at specific time
on Apr 16, 2014 at 8:05:04 pm

Hi - I hope this hasn't been answered above. Very helpful thread!

So I'm trying to have a simple translation expression evaluate between a start and stop time, but when it ends, I want the object to retain it's translation it ended up with at the end of the expression's evaluation. As it currently is, the object jumps back to it's original position, which is no surprise....!

Any help would be greatly appreciated!

beginTime = 1;
endTime = 30;

x = transform.position[0]
yOrigin = 520;
yDelta = -10;

if (beginTime &lt;= timeToFrames(time) && timeToFrames(time) &lt;= endTime ) {

newY = yOrigin + timeToFrames() * yDelta; }
else newY = yOrigin;

[ x, newY]




Return to posts index

Cameron Walser
Re: start/stop expression at specific time
on Apr 16, 2014 at 8:28:39 pm

Oh shoot - I should add this new problem in too.

I want to add a random value to the position's translation, but the expression recalculates the random value that it adds every time. See below.

Basically I want to create an expression that translates a layer a random amount between a specified start and stop time (which ideally will depend on the layer's own start and stop time, so I can randomize that as well) - Then I can duplicate the hell out of that layer, and slide the layers in time, and have a whole bunch of layers translating different amounts...

PS the garbled characters should be <
something odd going on here in ASCII land

beginTime = inPoint;
endTime = outPoint;

x = transform.position[0]
yOrigin = 520;
yDelta = random (-10,10);

if (beginTime &lt; = time && time &lt; = endTime ) {

newY = yOrigin + timeToFrames() * yDelta; }
else newY = yOrigin;

[ x, newY]


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Apr 16, 2014 at 8:46:44 pm

I think it would look like this:


beginTime = 1;
endTime = 30;

yOrigin = 520;
seedRandom(index,true);
yDelta = random(-10,10);

f = timeToFrames(time);

if (f <= beginTime){
d = 0;
}else if (f <= endTime){
d = f - beginTime;
}else{
d = endTime - beginTime;
}
yNew = yOrigin + d*yDelta;
[value[0],yNew]


Although, if you wanted to key it to the layer's in point, something like this might be better:


dur = 30;

yOrigin = 520;
seedRandom(index,true);
yDelta = random(-10,10);

f = Math.max(timeToFrames(time-inPoint),0);
d = (f < dur) ? f : dur;
yNew = yOrigin + d*yDelta;
[value[0],yNew]



Dan



Return to posts index

Cameron Walser
Re: start/stop expression at specific time
on Apr 16, 2014 at 9:24:12 pm

Awesome thank you - one more quick question Dan -

1) How in the world do you have time to answer all these questions?!
:)


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Apr 16, 2014 at 9:31:05 pm

Sorry, no time to answer... ;-)



Return to posts index

Cameron Walser
Re: start/stop expression at specific time
on Apr 17, 2014 at 7:18:01 pm

Dan maybe you'll know the answer to this one -
I've made a functional comp with the expression, finally, and the expression references Expression Sliders on a null layer. So after I duplicate the layer a thousand times, I can simply adjust the sliders on the one layer. Here's the question - what if I want to change the expression itself? Do I have to re-duplicate the layer 1000 times? Or is there some way to reference a "Master" expression?

Latest expression posted just FYI

dur = 1;
x = thisComp.layer("NULL PARAMETERS").effect("X_Origin")("Slider");
f = (timeToFrames(time));
yOrigin = 500;
seedRandom(index,true);


y = linear(time, inPoint, inPoint + dur, thisComp.layer("NULL PARAMETERS").effect("Y_Origin")("Slider"), (thisComp.layer("NULL PARAMETERS").effect("Y_Origin")("Slider") - (random (thisComp.layer("NULL PARAMETERS").effect("Least")("Slider"), thisComp.layer("NULL PARAMETERS").effect("Most")("Slider")) ) ) );

[x, y]


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Apr 17, 2014 at 7:24:23 pm

There are hacks for a master expression, like putting it in a hidden text layer, but it's really inefficient. Faster than re-duplicating all the layers would be to change the expression in one layer, make sure that property is selected, Edit > Copy Expression Only, select all the other layers, Edit > Paste.


Dan



Return to posts index

Christoph Müller
Re: start/stop expression at specific time
on Apr 13, 2015 at 1:58:06 am

I know that this is an old thread, still I am trying to get the parenting-expression to work and can't figure out what I am doing wrong. The 'child-layer' follows the 'Master-layer' but before, it changes its position and at the end it goes back again to where it was...

This is what I use on the 'child-layer':

timeToStart = 2.5;
timeToEnd = 6 ;

if (time > timeToStart && time < timeToEnd)
{
thisComp.layer("MASTER").toComp([0,0,0])
}else{
value
}

It seems that the change in position is related to the 'toComp([0,0,0])'-part. How can I make it work to stay at its place?


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Apr 13, 2015 at 3:48:38 am

I can't tell exactly what you're after, but maybe this will get you closer:


timeToStart = 2.5;
timeToEnd = 6 ;

if (time > timeToStart && time < timeToEnd){
thisComp.layer("MASTER").toComp([0,0,0]);
}else if (time >= timeToEnd){
thisComp.layer("MASTER").toComp([0,0,0],timeToEnd);
}else{
thisComp.layer("MASTER").toComp([0,0,0],timeToStart);
}



Dan



Return to posts index

Christoph Müller
Re: start/stop expression at specific time
on Apr 13, 2015 at 2:55:40 pm

Thanks for your reply Dan. It definitely brings me closer but it's not what I am looking for. What I actually want to achieve is the following:

A character plays frisbee. The frisbee flies towards the character and at a given time he grabs it, moves it around a bit and fires it again into some other direction. So, the frisbee should be able to move on its own but when the character grabs it, it should move along with the hand. Then when he fires the frisbee again, it should be able to move on its own again. Is this possible?


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Apr 13, 2015 at 4:51:57 pm

I think there's a piece missing. How do the frisbee and the character get to the same place at the same time?



Return to posts index

Christoph Müller
Re: start/stop expression at specific time
on Apr 13, 2015 at 5:44:47 pm

The characters hand and the frisbee are two seperate layers. Each one would be individually animated with keyframes. The frisbee comes in from point A to point B which is very close to the grabbing hand. At this point it follows the hand movement and its keyframes (position, rotation) till it is thrown away again. and goes from C to D.

Does that make sense?


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Apr 13, 2015 at 5:57:41 pm

I must be missing something, because I think that's exactly what your original expression does. The layer does its own thing before 2.5 seconds and after 6 seconds. In between, it rides along with MASTER.

Dan



Return to posts index

Christoph Müller
Re: start/stop expression at specific time
on Apr 13, 2015 at 6:04:45 pm

The problem I have is that the frisbee does not stay at the positioned keyframe (B) but moves to another place in the comp when the parenting starts. And at the end of the parenting it goes back again to the original position instead of staying where it went with the parenting.


Return to posts index

Dan Ebberts
Re: start/stop expression at specific time
on Apr 13, 2015 at 6:18:02 pm

>The problem I have is that the frisbee does not stay at the positioned keyframe (B) but moves to another place in the comp when the parenting starts.

You want it to stay at B when the parenting starts? Sorry, I'm lost...

Maybe someone else can figure it out.

Dan



Return to posts index

Christoph Müller
Re: start/stop expression at specific time
on Apr 13, 2015 at 6:46:13 pm

lol. I made an AE file to show you what I meant and you know what, you are right (of course you are). Now everything is working as it should... Embarrassing. Sorry to have you bothered with a problem that actually didn't exist and thanks for your time.


Return to posts index

Clayton Krause
Re: start/stop expression at specific time
on Nov 7, 2016 at 6:35:34 pm

Great thread. Lots of information. I'm going to resurrect it with another question on delaying an expression.

What Dan posted up is fantastic, IF you know what frame you need to start something at. In my specific situation I do not know the specific frame...

I have 4000 little cubes scattered throughout my canvas. They are all duplicates with the same expression. The cubes are all solids with a Hue/Sat adjustment applied to it. There is an animated Null that goes from the bottom up to the top of the canvas. The expression for the lightness in the Hue/Sat reads-

When the Null Y pos exceeds a specific cube's Null Y pos, have the cube Hue/Sat lightness turn to a higher value. I got it working, but I want to add easing to that value. Instead of snapping from valueOff to valueOn, have it ease there.

I don't know the specific hit frame on each cube and ultimately if I did, that information would be useless as this expression which controls the lightness cannot be hard coded, but needs to revolve around the unique position of that unique cube in relation to the one animated null.

Anyone have any ideas on how to work this? If my description didn't make sense let me know and I'll post more about it.


Return to posts index

Clayton Krause
Re: start/stop expression at specific time
on Nov 7, 2016 at 7:08:00 pm

Sorry to be annoying and make a double post on this.

What I need to figure out (I think) is how to return the specific time that a conditional executes. What is the exact time that the null posY exceeds the cube posY and use that to stagger the ease -

stagger = specific time that null posY exceeds cube posY
easeIn(time-stagger, 0, 10);

Don't know how to get that information. In part because the variables don't get stored and are refreshed on each frame.

Thanks for any help!


Return to posts index

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