The Expressions Thread

Yea i forgot about removing the if/else

dorde said

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…

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

DOF = thisComp.layer("CONTROL_LAYER").effect("Checkbox Control")(1).value;
DOF ? value : 0;

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

Great idea Ben. Works like a charm.

Thanks!

Hi I’m wondering how I can edit the “shape” parameter of masks in expressions. If I click on shape I get a new window where I can set the end-points of the bounding box. Let’s say I want to place the mask according to the layer index, so that it moves 200 pixel to the right for each index increment.

Or maybe there are scripts who can help to place masks precisely.

Creattive said

Hi I’m wondering how I can edit the “shape” parameter of masks in expressions. If I click on shape I get a new window where I can set the end-points of the bounding box. Let’s say I want to place the mask according to the layer index, so that it moves 200 pixel to the right for each index increment.

Or maybe there are scripts who can help to place masks precisely.

You can set the shape of a mask to the shape of another mask using expressions. Or to a shape path IIRC. But to set the individual mask nodes, you need to use scripting.

Hi,
is there a script that changes all my expressions to absolute paths, e.g. converts to <comp(“Comp Name”)>
This way pre-composing layers with expressions would be much easier.

Creattive said

Hi,
is there a script that changes all my expressions to absolute paths, e.g. converts to <comp(“Comp Name”)>
This way pre-composing layers with expressions would be much easier.

Not as far as I know. It’s perfectly doable with scripting, but it’s unfortunately not quite as simple as a simple search and replace. You’d need to check for duplicate named comps, strings, comments etc. etc.

I’m thinking of posting some scripting tips here too. Is anyone interested?

felt_tips said

. Is anyone interested?

I sure am.

About the absolute paths: Maybe one can somehow set after effects to only generate absolute paths when pickwhipping, though it is helpful sometimes.
If I have the time I might write a script for those absolute paths, will post it here then.

Here is a good explanation of how to script for after effects:
http://library.creativecow.net/toula_jesse/AE-Scripting-1/1

Hi,

i would like to have an control layer from which you can select one layer from the composition to be activated. Does this work with the layer control expression effect and if yes, how?

Thank’s for your help! :slight_smile:

Creattive said
felt_tips said

. Is anyone interested?

I sure am.

About the absolute paths: Maybe one can somehow set after effects to only generate absolute paths when pickwhipping, though it is helpful sometimes.
If I have the time I might write a script for those absolute paths, will post it here then.

Here is a good explanation of how to script for after effects:

I’ll have a go too if I get a minute.

How to use an Expression Layer Control

Leupsi said

Hi,

i would like to have an control layer from which you can select one layer from the composition to be activated. Does this work with the layer control expression effect and if yes, how?

Thank’s for your help! :slight_smile:

It depends what you want to do with the layer reference. So here’s an example that uses an Expression Layer Control to set the position of a layer.

Make a 3D layer, and put an Expression Layer Control on it. Then put the following expression on the Position property of that 3D layer. You’ll need a try / catch statement because if you try to refer to an Expression Layer Control when it’s set to None, you’ll immediately get an error. The catch part of the statement catches that error and executes some code, in this case setting the variable L to null.

The long way

try{
	L = effect("Layer Control")("Layer");
}catch(e){
	L = null;
}

if(L != null) {
	tPos = L.toWorld(L.anchorPoint.value);//get the world pos of the selected layer
} else {
	tPos = value;
}

tPos;

The short way… exactly the same, just more compact

try{L=effect("Layer Control")(1)}catch(e){L=null}
L ? L.toWorld(L.anchorPoint) : value;

When you set the Expression Layer Control to be another layer in the composition, the first layer will automatically jump to its world position. (In this simple example, the layer with the expression on should not have a parent layer - that requires extra code)

Creattive said

Hi,
is there a script that changes all my expressions to absolute paths, e.g. converts to <comp(“Comp Name”)>
This way pre-composing layers with expressions would be much easier.

Why not to use such expression?
c = thisComp; 
x = c.layer("Null 2").transform.opacity; //this path only for example
And when you pre-comp layers, just change "thisComp" to "comp("name")".
DOGmotion said
Creattive said

Hi,
is there a script that changes all my expressions to absolute paths, e.g. converts to <comp(“Comp Name”)>
This way pre-composing layers with expressions would be much easier.

Why not to use such expression?
c = thisComp; 
x = c.layer("Null 2").transform.opacity; //this path only for example
And when you pre-comp layers, just change "thisComp" to "comp("name")".

yeah that would be possible, but that would take the same time as replacing thisComp with comp(“name”).
The problem is that I pickwhip the values and after effects automatically uses thiscomp.

DOGmotion said
Creattive said

Hi,
is there a script that changes all my expressions to absolute paths, e.g. converts to <comp(“Comp Name”)>
This way pre-composing layers with expressions would be much easier.

Why not to use such expression?
c = thisComp; 
x = c.layer("Null 2").transform.opacity; //this path only for example
And when you pre-comp layers, just change "thisComp" to "comp("name")".

Still a little on the manual side. :slight_smile:

Creattive said

Hi,
is there a script that changes all my expressions to absolute paths, e.g. converts to <comp(“Comp Name”)>
This way pre-composing layers with expressions would be much easier.

check this out http://aescripts.com/duplicate-with-connections/

What are expressions?

I’m going to write a line or two about expressions in general, because no expression reference would be complete without it. If you have any thoughts to add, please reply below and I can include some parts in here.

Overview

Expressions are a means of creating relationships between properties in After Effects, which can be applied to any property that has a stopwatch - in other words, any property that is keyframeable. The easiest way to create an expression on a property is by alt-clicking the stopwatch. When you do this, a default expression will be written that refers to the property itself. You don’t even have to know expression language to get started; you can use the expression pick-whip to pick other properties and the code will automatically be written to link to that property. This is a great way to learn.

Once you get good at expressions, you can start to write complex relationships and do certain things that are almost impossible (or at least prohibitively time-consuming) with classic key-framing techniques. In fact, more advanced After Effects users will often set up complex systems with simple top-level expression controls, allowing easier experimentation with the look or movement without having to change hundreds of keyframes every time.

Language

Once you get further, you’ll find that the After Effects expresssions language is ECMA script based. That means its syntax is almost identical to that of Javascript. You can use most Javascript commands and structures in expressions. The object model is very similar too.

After Effects Specific Commands

On top of the Javascript-like properties and functions, expressions language has its own After-Effects-specific set of methods and properties. These can all be found in the dropdown menu that appears to the left of any expression. Full details of how to use these can be found in the After Effects Expressions guide.

After Effects also has several “Expression Effects”. These can be applied to layers like any other effect and they’re found under the Effects menu in Expressions. They don’t actually do anything, but instead act as informational properties that the expression language can use to link other properties to. For instance, you could create an Expression Point Control on a null layer, and use this to control the position of several other layers. Or you could create an Expression Slider Control and use its value to control the movement randomness of a multitude of other layers, even in other compositions.

Limitations

One of the things that sometimes foxes people who are familiar with other types of programming, particularly Action Script for Flash, is that After Effects expression variables do not persist from frame to frame. Each frame starts its calculations afresh. This means that it’s difficult in After Effects to create physical systems that include speed, momentum, friction etc. It’s not impossible, but it requires making long inefficient loops on every frame, that can get out of hand in long compositions.

For Videohive

Expressions are so useful for lots of reasons, especially to Videohive authors. Example: Imagine you are creating a project whose color scheme you would like to be able to change throughout. This might mean that the user would need to change the color of literally hundreds of layers, that might be deeply nested in the composition structure.

With expressions, you can set up a system where each layer that needs to change color is linked to an Expression Color Control. Changing this Expression Color Control will now change all linked colors in the project. If your color scheme consists of five colors, you can do the same for all five colors. If you want to take it a step further, you can then link the five top level Expression Color Controls to an Expression Slider Control, which you might name “Color Scheme” and write expressions to link the five Expression Color Controls to it. So now, when the Color Scheme Slider Control is set to three, for instance, the five Expression Color Controls change respectively to the colors of the third color scheme, which in turn changes the color of all the layers that you have linked to them. Before you can say “Bingo!”, you’ve changed the look of your entire project to the third color scheme at the click of a button.

It doesn’t have to just be for colors. You can adjust pretty much anything you can think of.

Felt_tips that’s very useful post! Thanks a lot!

Script resources

  • http://www.redefinery.com/ae/
  • http://www.aenhancers.com/viewforum.php?f=3
  • http://aescripts.com/
  • http://www.mamoworld.com/
  • http://www.crgreen.com/aescripts/
  • http://www.nabscripts.com/downloads_en.html
  • http://www.petertorpey.com/projects/ae/
  • “You can’t even change a typeface with scripting, as far as I’m aware.”

    Actually, you can.

    In this post, I show how in an example:

    ToddKopriva said

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

    Actually, you can.

    In this post, I show how in an example:

    Thanks for that, Todd. That one had completely passed me by! That’s going to come in useful, I think.