The Expressions Thread

Thanks felt
What if on this code i want to specify a number of frames (say 61 frames for in animation and 55 frames for out animation) ? What you have currently provided is the seconds (2 seconds) i guess.

Thatā€™s a bit more difficult. Weā€™re using a random seed to generate the numbers and the random seed is based on time. You could do something cunning with time and rounding, but I think the better option is to make a new effect slider and base the random seed on that.

tString = "";
tChars = ["A","B","C","D","E","F","0","1","2","3","4","5","6","7","8","9"];
highArbitraryNum = 993.4;
while(tString.length<10) {
	seed = Math.floor(effect("random seed")(1).value*highArbitraryNum+tString.length);
	seedRandom(seed,true);
	tString += tChars[Math.floor(random(tChars.length))];
}

Then youā€™d need to keyframe that effect. The thing is that with a simple keyframe, it will still change every frame, so you might want to put an expression like Math.floor(value) on the expression, or you could use held keyframes. The expressions way willl effectively round the value to a whole number and if your keyframes make the number increase slowly enough, then the value wonā€™t change every frame and neither will your text animation that is based on it.

Just useā€¦

framesToTime(frameNumber)

to get the value of the frame in seconds.

Use the little blue box at the bottom right, alternatively hit End on your numeric keypad (usually just below Home). You can do End on a Macbook keyboard by pressing Function and right arrow. Function and left arrow is home. Function and the up and down arrows are page up and page down (sorry not sure for a PC laptop, but Iā€™m sure itā€™s doable). Or just select a post and hold down J.

Thanks felt

Could you also please guide me where to put this code on the below? And how to use?
Sorry my knowledge on expressions is very week. Basically i want to input different number of frames for the in and out animation,

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 {
tSampleT = L.inPoint+SrcInDur+Src.frameDuration;
}

Thank you Felt, really appreciated :smile:

After Effects uses seconds, not frames for time, so if you want to use frames you need to do a conversionā€¦

Hereā€™s one wayā€¦

tSecs = framesToTime(124); //124 frames in seconds

Hereā€™s anotherā€¦

tSecs = 124*thisComp.frameDuration; // 124 frames in seconds

To go the other way, use timeToFrames() or divide by thisComp.frameDuration

You apply the expression to the Time Remap property of a layer that has a compostion (the composition that you want to control) as its source. You put content in the source composition that consists of an animate in, animate out and a middle section. You note the timings of these three sections, and customize the lines that start SrcInDur = and SrcOutDur = respectively. The section in the middle loops and stretches to make the content fit the duration between the layerā€™s in and out points.

Beyond that, I canā€™t really help, Iā€™d have to open your project up and do your work for you! This thread is designed primarily as a learning resource, and learning is partly about learning stuff thatā€™s at the right level for you. If itā€™s still difficult for you to figure out, you probably need to back up a few steps and get familiar with some simpler expressions to start with.

Thanks alot felt.
I figured out how to work with this code. Hopefully in next couple of weeks, i will upload my new project which uses this code.

Hi Felt,

Sorry to keep you bugging about this.
I tried the below expression. And it worked. But while i was recording the tutorial, i found out that my expression donā€™t work properly if i moved the layer a bit to the right in the timeline. That is, it worked fine when the first frame of this layer started at first frame of the timeline. But if i move the layer so that the first frame of the layer starts at 2 or 4 seconds in the timeline, it doesnā€™t work any more. The whole middle portion (without any animation) just becomes blank and transparent. But the end animation works fine.

Any idea why?

Below is the expression i used. 56 frames are the in animation. 26 frames are the end animation.

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

SrcInDur = framesToTime(56); //the duration of the in animation
SrcOutDur = framesToTime(26); //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 {
tSampleT = L.inPoint+SrcInDur+Src.frameDuration;
}

Hi Aeyaz,

I can see why thatā€™s not working. There are so many versions of this code now, I canā€™t remember even why this one is written like that.

Try this.

L = thisLayer; 
Src = L.source;
SrcDur = Src.duration;
LDur = L.outPoint-L.inPoint;
SrcInDur = framesToTime(56); //the duration of the in animation
SrcOutDur = framesToTime(26); //the duration of the out animation
SrcLoopDur = SrcDur-SrcInDur-SrcOutDur; //the rest is the loop

if(time < L.inPoint+ SrcInDur) { //in animation
	tSampleT = time-L.inPoint; //sample time is just the value
} else if(time > L.outPoint-SrcOutDur) { //out animation
	LOutElapsed = time - (L.outPoint-SrcOutDur);
	tSampleT = SrcDur-SrcOutDur + LOutElapsed;
} else {
	tSampleT = SrcInDur+Src.frameDuration;
}

-f.

Thanks felt.
It works fine now. After going through the new code, even i understand what was the problem earlier.
Thanks for your help. The project is done uploaded. Waiting for the review.

I am fairly new to expressions. I am working with this template (http://videohive.net/item/infographics-infocharts-package/3945627)

I am working on Pie Chart 02 and want to change the pie to have 8 sections instead of 10. There is a place where it seems like I should be able to change the value but I canā€™t figure it out. Here is a screen shot of the field. I will also cut and paste the expression below.

if ((thisComp.layer(ā€œSETTINGSā€).effect(ā€œNumber of x Valuesā€)(ā€œADBE Slider Control-0001ā€).value < 10) || (thisComp.layer(ā€œSETTINGSā€).effect(ā€œNumber of x Valuesā€)(ā€œADBE Slider Control-0001ā€).value > 10)){
thisComp.layer(ā€œSETTINGSā€).effect(ā€œNumber of x Valuesā€)(ā€œADBE Slider Control-0001ā€).value = 10} else {
thisComp.layer(ā€œSETTINGSā€).effect(ā€œNumber of x Valuesā€)(ā€œADBE Slider Control-0001ā€).value =thisComp.layer(ā€œSETTINGSā€).effect(ā€œNumber of x Valuesā€)(ā€œADBE Slider Control-0001ā€).value}

Please help!

This expression does nothing.

Here is what it says in english:
If value is not 10, set value to 10. Otherwise (if value is 10) set value to value (i.e 10)

So the expression sets the value to 10ā€¦ which you donā€™t need an expression for. Delete the expression and change the value to 8. But itā€™s anyoneā€™s guess what effect changing the value to 8 might have.

Hello guys,
I was interesting to use a local and global checkbox for colour controls inside of each comp and outside on the main comp.
Does anybody can help me with this.
I appreciate it.
Thanks

So you want to let your customers choose whether they want to customize the color of something by a global color controller inside the main comp or a local controller inside the comp of that thing?

Yes. Exactly!

Iā€™ve done that before, I added to the local panel controller a checkbox that if you uncheck it, the color of the object will be disconnected from the global color controller and connected to the local color controller.

(Click on the GIF for better quality)


(I locked the Effects panel to the global controller that is in the Main Comp, just to not make the GIF too long)

Here is the expression that appears in the GIF:

Global = ;			//The Global Color Controller in your Main Comp
Local = ;			//The Local Color Controller in the individual comps
Check = ;			//The Checkbox next to the Local Color Controller

if(Check == 1) {

	Global
} else {

	Local
}

I hope you find this clear enough :+1:

local = thisComp..... ; // put here local color control path
glob = comp("bla-bla")..... ; // put here global color
c = comp("bla-bla").... ; // path to checkbox
x = c ? local : glob; // if checkbox is ON local color is used

UPD: oops, Iā€™m to late :slight_smile:

Thank you guys, i will try it right now!!

Hi friends, i need some help. How can i create an expression to simply stretch a layer duration from a time remapped layer?