The Expressions Thread


#1

Ask Your Expressions and Scripting Questions Here.

It has been requested in various threads now, that I make an expressions sticky thread. So here it is.

For those of you that don’t know, expression language is a Javascript based language that After Effects uses to make simple (or complicated) dynamic relationships between comps, layers, and properties. It can take your After Effects to another dimension, and it’s particularly useful for templates. Making complex templates easy to organise and customise for less experienced users is easy with expressions.

I might add a few scripting bits and pieces in here too. Scripting is also a very powerful way of extending After Effects capabilities. More powerful than expressions, in fact, because scripting can automate most of what the user can do in Ae. But because scripting is a much more complicated beast, most of this thread will be dedicated to expressions.

Above all, the point of this thread is to collect the answers to those frequently asked questions on the forums. Some buyers might find it useful, but it’s basically aimed at Videohive authors.

Like the Essential Resources thread, I’ll collect the best stuff in this post. I’ll edit and format the best responses and then link to them from this post as a kind of expressions knowledge-base. Please make sure to format any code you post inside “pre” tags.

Expressions

Scripting


The Expressions Thread
The Expressions Thread
#2

Finally :slight_smile:


#3

Great idea! Those things are not easy to find. This will be a great place for that:) Don’t let it slip:)


#4

Awesome idea, thank’s to the founders! :slight_smile:


#5

Good Idea :wink:


#6

I’m waiting for the sources.,


Thank you so much felt, :slight_smile: :slight_smile:


#7

This thread will be more useful!


#8

Thanks for posting, really a nice idea to share. :slight_smile:


#9
crazydesigns said

I’m waiting for the sources.,


Thank you so much felt, :slight_smile: :slight_smile:

Well we need some questions first! Expression questions usually pop up at a rate of about 1 a week, so you shouldn’t have to wait for long.


#10

I’ll start with a simple one. :slight_smile:

I am assuming it is beyond the power of an expression but no matter, for conversation’s sake - can I control a layer’s attributes like the 3D box, motion blur and shy layer switch? Would be e nice one.


#11

Once i’ve asked how to set minimum and maximum value in a expression control.
The easiest and correct answer from DogMotion was:

clamp(value, min=0, max=255)

#12

How to set minimum and maximum values for an Expression Slider Control

clamp(value, min=0, max=255);

…sometimes I use a little bit modified version of this expression…
For example, you want “teach” slider to take only whole numbers from 1 to 5.
So this expression help you:

round = Math.round(value);
min = 1; //minimum value
max = 5; //maximum value
clamp(round, min, max);

edit:

Or the whole of that last bit in one line…

clamp(Math.round(value), min = 1, max = 5);

Note: You don’t need the min = and max=, but it can be helpful in remembering which arguments are which.

(-f.)


#13
InlifeThrill said

can I control a layer’s attributes like the 3D box, motion blur and shy layer switch? Would be e nice one.

maybe this is what you are looking for.


http://aenhancers.com/viewtopic.php?f=3&t=348


#14

Sweet! Thanks dude :slight_smile:


#15
InlifeThrill said

can I control a layer’s attributes like the 3D box, motion blur and shy layer switch? Would be e nice one.

Yep. Not possible with expressions, but perfectly possible with scripting.


#16

Hi, everybody!
I know that change text font by expression it is impossible. But I thought about this thing very often. And understand some… So when I will be at my main computer, and test this expression. I will wrote it here with details. But know, I don’t think it will work fine…
So for now… it’s only idea…


#17
DOGmotion said

Hi, everybody!
I know that change text font by expression it is impossible. But I thought about this thing very often. And understand some… So when I will be at my main computer, and test this expression. I will wrote it here with details. But know, I don’t think it will work fine…
So for now… it’s only idea…

You can’t even change a typeface with scripting, as far as I’m aware.


#18

I’m about to finish my new project which contains cameras with depth of field.

I would like to have control layer with checkbox control to disable depth of field on all cameras. Is that possible? How?

If not, I can explain to buyers in help file how to disable depth of field on all cameras manually or I can create 2nd final composition (ready for render) which can contains duplicated compositions with disabled depth of field.

So it’s not big problem for me, but checkbox would be awesome. I dont know how. Anyone has an idea?

I’m afraid that it can’t be done with expression because depth of field is on/off value and there is no way to add any expression to it.

Thanks


#19

How to globally set depth of field

dorde said

I’m about to finish my new project which contains cameras with depth of field.

I would like to have control layer with checkbox control to disable depth of field on all cameras. Is that possible? How?

@Dorde:

DOF = thisComp.layer("CONTROL_LAYER").effect("Checkbox Control")("Checkbox");

if( DOF == 1) {
    true;
} else {
    false;
}
dorde said

Thanks, it works. Also little shorten expression works:

thisComp.layer("CONTROL_LAYER").effect("Checkbox Control")("Checkbox")

Edit: That’s because a Checkbox evaluates to true or false anyway. (-f.)

felt_tips said

@Dorde: You could put the expression on the aperture or blur amount instead in CS3. Same effect.

//on the aperture property
DOF = thisComp.layer("CONTROL_LAYER").effect("Checkbox Control")(1).value;
DOF ? value : 0;
felt_tips said

@Mo… you often need the .value on the end of a checkbox control, otherwise you’re testing the property object and not its value. It’s usually okay, but you can sometimes run in to difficulties.

Also… you can keep your code much shorter with ternaries…

if(DOF == true) {
     x = 12;
} else {
     x = 3;
}
x = DOF ? 12 : 3; //this line does the same as the lines above.

#20

Thanks, it works. Also little shorten expression works:

thisComp.layer(“CONTROL_LAYER”).effect(“Checkbox Control”)(“Checkbox”)

But only in cs5. I made project in cs3. There is no stopwatch icon next to deph of field in cs3 and cs4, and I can’t add expression to it…