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.
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.
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.
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…
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.
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.
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.