The Expressions Thread

amberija said
Pixelit_Plus said

That exactly what I was looking for!!! BIG Thanks!!!

Is there a way to help me with a second “object’s x position” slider?

What I need is object x position to REPLACE A FUNCTIONAL slider used as a background selector which background frames are in another comp.
So has to be step limited lets say 1 to 10 (every frame links a background choice)

This slider (used in a control panel) is a “selector” used in conjunction
with this script line:
state=comp(“1_For_Customization”).layer(“Controls”).effect(“Background”)(“ADBE Slider Control-0001”);
framesToTime(state);

WeTransfer Link of the slider surface selector already working which I want to replace an object x 10 stepped position:
http://we.tl/IcI1RdQ3DM

What you basically need is an switch function. I used it in my universal counter in infographics kit template. I needed different currency sign in suffix (dollar, euro, yen etc). Drivable by slider control. So that value on slider was: 0=no suffix, 1=dollar, 2=euro etc.

switch(expression) {
case n:
code block
break;
case n:
code block
break;
default:
default code block
}

Thanks for being so kind to help me.

I am not good in scripting so I did’nt manage to follow your guidance.
For example in the given script-lines I cant see where to place 1=image-1, 2=image2 etc.

But as I have already succeed in doing that with a slider my need is only to replace the slider
with an “object-slider” moovin in STEPS (10 steps)to x axis.
If you download the wetransfer-link you will see the slider working and the object-slider "waiting"
to be connected.
http://we.tl/IcI1RdQ3DM

Thanks again!

In your case there will be no switch. Simple as is. Put in background com. Layer Textures - timeremap this code:

x=comp("1_For_Customization").layer("Surface_Slider ").transform.xPosition/10;
framesToTime(x);

Super Thanks!!!

Hello folks, i want to pre-compose a composition with in-out animations.
Ex: I’ve created a 30 seconds layer, I’ve put keyframes in first 10 frames and in last 10 frames.
So I want to increase and decrease the layer time in a pre-composed comp just dragging out point, but keeping in-out animations. Could you help me?

DiegoMirnov said

Hello folks, i want to pre-compose a composition with in-out animations.
Ex: I’ve created a 30 seconds layer, I’ve put keyframes in first 10 frames and in last 10 frames.
So I want to increase and decrease the layer time in a pre-composed comp just dragging out point, but keeping in-out animations. Could you help me?

Hello! What kind of animation you have? Do timeremap works for you?

amberija said
DiegoMirnov said

Hello folks, i want to pre-compose a composition with in-out animations.
Ex: I’ve created a 30 seconds layer, I’ve put keyframes in first 10 frames and in last 10 frames.
So I want to increase and decrease the layer time in a pre-composed comp just dragging out point, but keeping in-out animations. Could you help me?

Hello! What kind of animation you have? Do timeremap works for you?

Yeah, time remap could work, but i want to precompose this time remap(first 10 frames and last 10 frames), in a comp I don´t need to drag keyframes, just increase or decrease layer time.

DiegoMirnov said
amberija said
DiegoMirnov said

Hello folks, i want to pre-compose a composition with in-out animations.
Ex: I’ve created a 30 seconds layer, I’ve put keyframes in first 10 frames and in last 10 frames.
So I want to increase and decrease the layer time in a pre-composed comp just dragging out point, but keeping in-out animations. Could you help me?

Hello! What kind of animation you have? Do timeremap works for you?

Yeah, time remap could work, but i want to precompose this time remap(first 10 frames and last 10 frames), in a comp I don´t need to drag keyframes, just increase or decrease layer time.

I made it as I understood you. Now you have different in and out points for the same copies of one layer that is precomoped and “timeremaped”. Inside it has in and out animations for 10 frames. In code you see 10 - thats your in and out animations. Change it to desired number as you want to tune you animation.

FF = 10*thisComp.frameDuration;
if (time=inPoint && time<=inPoint+FF) {time-inPoint}
else if (time=outPoint && time>=outPoint-FF) {thisLayer.source.duration+time-outPoint}

The question is “what does the animation do when it’s not animating in and out?”. If it just stays still, it’s a pretty easy problem to solve.

Assuming your precomp has the in animation at the start (in the first 10 frames) and the out animation at the end (in the last 10 frames), but we don’t know what’s happening in the middle. The following method puts the in and out animation in the right place, and simply telescopes the bit in the middle. If the bit in the middle is just a hold, then all good. The precomp should be at least 20 frames long, or you might get unexpected results.

//On the time remap property
L = thisLayer;
t = time;
animLength = 10;
animLength *= thisComp.frameDuration;
LDur = L.outPoint-L.inPoint;
MidDur = LDur - animLength*2;
if( t>=L.inPoint && t<= L.inPoint+animLength) {t-L.inPoint} 
else if( t>L.inPoint+animLength && t=L.outPoint-animLength && t<=L.outPoint) {t-(L.outPoint-animLength)}
else 0;
amberija said
FF = 10*thisComp.frameDuration;
if (time=inPoint && time<=inPoint+FF) {time-inPoint}
else if (time=outPoint && time>=outPoint-FF) {thisLayer.source.duration+time-outPoint}

Don’t you mean…

FF = 10*thisComp.frameDuration;
if (time>=inPoint && time<=inPoint+FF) {time-inPoint}
else if (time<=outPoint && time>=outPoint-FF) {thisLayer.source.duration+(time-(outPoint-FF))}

…? You used an = instead of a >= . If you did want to use an ‘equals’ it would need to be a comparative equals, i.e. == . At the moment, you’re setting time to be inPoint and then comparing it to a different value. In the above, both of your if statements will evaluate to false and the expression will always return FF.
Also, shouldn’t the time to subtract from the layer source duration be the time past the outPoint- FF, not the time past the outPoint.

With my adjustment above the case where time >inPoint+FF and time <outPoint-FF isn’t really covered. (i.e. when not animating in or out). The expression will currently return the value FF. That’s probably a decent thing to return, but it’s probably good to make it explicit, with the addition of…

else FF;
felt_tips said
amberija said
FF = 10*thisComp.frameDuration;
if (time=inPoint && time<=inPoint+FF) {time-inPoint}
else if (time=outPoint && time>=outPoint-FF) {thisLayer.source.duration+time-outPoint}

Don’t you mean…

FF = 10*thisComp.frameDuration;
if (time>=inPoint && time<=inPoint+FF) {time-inPoint}
else if (time<=outPoint && time>=outPoint-FF) {thisLayer.source.duration+(time-(outPoint-FF))}

…? You used an = instead of a >= . If you did want to use an ‘equals’ it would need to be a comparative equals, i.e. == . At the moment, you’re setting time to be inPoint and then comparing it to a different value. In the above, both of your if statements will evaluate to false and the expression will always return FF.
Also, shouldn’t the time to subtract from the layer source duration be the time past the outPoint- FF, not the time past the outPoint.

With my adjustment above the case where time >inPoint+FF and time <outPoint-FF isn’t really covered. (i.e. when not animating in or out). The expression will currently return the value FF. That’s probably a decent thing to return, but it’s probably good to make it explicit, with the addition of…

else FF;

True words, felt! With this thread and your help I hope I will enhance my expression!
I wrote that late night, tested and it worked for me) I like your approach for that solution. But I would also to hear from you - will the length of code reduce speed in viewport. I see it, for example, in bounce expression when there are too many objects evaluated by it.

//On the time remap property
L = thisLayer;
t = time;
animLength = 10;
animLength *= thisComp.frameDuration;
LDur = L.outPoint-L.inPoint;
MidDur = LDur - animLength*2;
if( t>=L.inPoint && t<= L.inPoint+animLength) {t-L.inPoint} 
else if( t>L.inPoint+animLength && t=L.outPoint-animLength && t<=L.outPoint) {t-(L.outPoint-animLength)}
else 0;

Hi Felt, I´ve created 2 comps.

Comp1 has keyframes in position, scale and rotation :
In: 10 frames
Mid: 50 frames
Out: 10 frames

So i’ve created a Comp2, just a precomposed Comp1, enabled time remap and applied the expression above. The idea is maintain the in-out animations and stretch the middle, but this message appear:

After Effects warning: Expected: ; Expressiondisabled.

Error ocurred at Line 8.

Comp: 'Comp2"

Layer: 1(‘Comp1’)

Property: ‘Time remap’

What is wrong here?

Thank you Felt and Amberija!

amberija said
felt_tips said
amberija said
FF = 10*thisComp.frameDuration;
if (time=inPoint && time<=inPoint+FF) {time-inPoint}
else if (time=outPoint && time>=outPoint-FF) {thisLayer.source.duration+time-outPoint}

Don’t you mean…

FF = 10*thisComp.frameDuration;
if (time>=inPoint && time<=inPoint+FF) {time-inPoint}
else if (time<=outPoint && time>=outPoint-FF) {thisLayer.source.duration+(time-(outPoint-FF))}

…? You used an = instead of a >= . If you did want to use an ‘equals’ it would need to be a comparative equals, i.e. == . At the moment, you’re setting time to be inPoint and then comparing it to a different value. In the above, both of your if statements will evaluate to false and the expression will always return FF.
Also, shouldn’t the time to subtract from the layer source duration be the time past the outPoint- FF, not the time past the outPoint.

With my adjustment above the case where time >inPoint+FF and time <outPoint-FF isn’t really covered. (i.e. when not animating in or out). The expression will currently return the value FF. That’s probably a decent thing to return, but it’s probably good to make it explicit, with the addition of…

else FF;

True words, felt! With this thread and your help I hope I will enhance my expression!
I wrote that late night, tested and it worked for me) I like your approach for that solution. But I would also to hear from you - will the length of code reduce speed in viewport. I see it, for example, in bounce expression when there are too many objects evaluated by it.

Longer expressions will generally take longer to evaluate, yes.

As far as I’m aware, there are two stages - first the code needs to be converted (i.e. the plain english you type is translated into a bunch of Javascript ‘tokens’ - computer instructions basically), that series of tokens is then evaluated as a program. I don’t know for certain which takes longer, but I could well imagine it’s the first part.

In that respect, it’s probably a good idea to keep code as short as possible - i.e. with a minimum of fluff, short variable names etc. Also, it’s a very good idea to keep the actual concept of the code efficient. Don’t do a load of unnecessary stuff, and try and think of a succinct way to do things.

Generally though, unless you’re getting up to complex expressions of several 10s of lines long (or even hundreds), that contain tricky stuff like repeats, recursive calls etc. then the execution time isn’t going to be particularly significant.

A good example of where it’s a great idea to keep your code as efficient as possible is coding text animations, where each expressions is iterated for each of the units in your text, for each iteration of motion blur. If you have 40 letters and 48 iterations of motion blur, that’s 1920 times that your expression is going to execute… PER FRAME. In a 30 second animation, the expression will be evaluated 1.4 million times.

I have a feeling that what changed in the latest version of CC regarding expressions is that the converting stage (stage 1) is now cached, whereas before I suspect they were re-converted with each iteration. Anyway, one way or another expressions got a lot faster recently.

DiegoMirnov said
//On the time remap property
L = thisLayer;
t = time;
animLength = 10;
animLength *= thisComp.frameDuration;
LDur = L.outPoint-L.inPoint;
MidDur = LDur - animLength*2;
if( t>=L.inPoint && t<= L.inPoint+animLength) {t-L.inPoint} 
else if( t>L.inPoint+animLength && t=L.outPoint-animLength && t<=L.outPoint) {t-(L.outPoint-animLength)}
else 0;

Hi Felt, I´ve created 2 comps.

Comp1 has keyframes in position, scale and rotation :
In: 10 frames
Mid: 50 frames
Out: 10 frames

So i’ve created a Comp2, just a precomposed Comp1, enabled time remap and applied the expression above. The idea is maintain the in-out animations and stretch the middle, but this message appear:

After Effects warning: Expected: ; Expressiondisabled.

Error ocurred at Line 8.

Comp: 'Comp2"

Layer: 1(‘Comp1’)

Property: ‘Time remap’

What is wrong here?

Thank you Felt and Amberija!

Hi Diego,

'Scuse the delay. A little sytax error and a little flaw in the logic. I should test my code out before I post it.

This should work for you…

//On the time remap property
L = thisLayer;
t = time;
animLength = 10;
animLength *= thisComp.frameDuration;
LDur = L.outPoint-L.inPoint;
MidDur = LDur - animLength*2;

if( t>=L.inPoint && t<= L.inPoint+animLength) {
\tt-L.inPoint;
} 
else if( t>L.inPoint+animLength && t=L.outPoint-animLength && t<=L.outPoint) {
\tL.source.duration + t-L.outPoint;
}
else 0;

Perfect! This expression works fine, thank you so much Felt!

DiegoMirnov said

Perfect! This expression works fine, thank you so much Felt!

Cool. :slight_smile:

Hi folks. I have similar thing (I guess) to do like Diego, but my hold is a loop. What I’m trying to make is to let buyers extend the loop/duration of “hold” time (which is actually a loop animation). All they should do is extend the comp’s out point.

I figured this is easiest with timeRemap but couldn’t figure out how. (If there is better and more logical way, even better)

I hope I was clear enough :slight_smile:

Hi Efekt,

That’s a bit more complicated. I’ll get back to you later on today or tomorrow with an answer. The problem is that you need to work out the nearest number of loops that fit, then you have the option, to 1) finish the whole animation before the out point, but keep it at the right speed, 2) to run the whole animation a bit slower to make it fit perfectly, or 3) just slow down the loop part to fit perfectly. I would favour option 2, but let me know which is better for you.

Thank you very much Felt. Actually, I’m open to everything. My basic idea is to make it easy for buyers to adjust length of loop part of comp. So, basically, I’m open to any solution. What I created in start is 3 comps, IN OUT and HOLD/loop, where buyers would extend HOLD/loop comp as desired, but then they would need to move OUT comp (and perfect fit also, holding shift and move), but I figured it was kind of complicated for them and time consuming. Honestly, I also wouldn’t like to make this overly complicated, so, as I said, any solution to this would be good for me. Thanks again.

'Scuse the delay, Efekt. I’ve been a bit busy. Actually, not true. I’ve been a bit lazy. :slight_smile:

Here’s the code. Put it on the time remap. I’ll come back and explain later. I’ve annotated the code, so you can probably work out what’s going on.

L = thisLayer; 
Src = L.source;
SrcDur = Src.duration;
LDur = L.outPoint-L.inPoint;

SrcInDur = 2; //the duration of the in animation
SrcOutDur = 2; //the duration of the out animation
SrcLoopDur = SrcDur-SrcInDur-SrcOutDur; //the rest is the loop

if(time < L.inPoint+ SrcInDur) { //in animation
    tSampleT = value; //sample time is just the value
} else if(time > L.outPoint-SrcOutDur) { //out animation
    LOutElapsed = time - (L.outPoint-SrcOutDur);
    tSampleT = SrcDur-SrcOutDur + LOutElapsed;
} else {
    // the loop in the middle
    LLoopDur = LDur - SrcInDur - SrcOutDur; //the duration of the loop bit
    LNumLoops = Math.floor(LLoopDur/SrcLoopDur); //how many whole loops fit?
    LNumLoops = Math.max(1, LNumLoops); //Make sure it's at least 1
    //Below: how much to stretch the loops by to fill the gap
    LLoopStretchFactor = (LNumLoops* SrcLoopDur)/LLoopDur; \t
    LLoopElapsed = time-(L.inPoint + SrcInDur); //time elapsed since loop start
    LLoopElapsed *= LLoopStretchFactor; // stretch this time by the stretch factor
        
    //sample time
    tSampleT = SrcInDur +(LLoopElapsed % SrcLoopDur); // peform a modulo and add the in duration
}

Hello guys,
is there any way to get the coordinates of the corners of an animated rectangle shape?

Thanks!