Errors ?

Learn how to deal with errors

1. AE CC 2015 (13.5)

Finally, Adobe decides to change the way expression errors are handled in AE, expressions toggle is no longer disabled if expression is not valid. Instead it displays a warning message and a warning icon next to the expression; clicking on it allows to access the error message.

It will also handle temporary errors; for example in the previous topic Subtitle track from an external file, when using markers, we created an if/else condition to avoid looking for marker 0.

{ if (m == 1) {“”} else

This is no longer required, as it will not disable the expression because of a unique event.

Read the official Adobe blog post here : http://blogs.adobe.com/aftereffects/2015/06/changes-to-expressions-in-after-effects-cc-2015-13-5.html

2. And before 2015 ?

To prevent unique or specific errors, you could make a set of if/else conditions; but if something is missing, for example applying the color expression from topic Color Palette / Swatches without having the color swatches in the timeline (or forgot to rename the layer to “colors”), that would not prevent from disabling the expression.

try {code} catch(err) {code}
acts like a conditional statement;
It tests the block of code for errors, if no errors it is executed,
if errors are found it will execute the alternate code specified in the catch(err)

read more about javascript errors here : JavaScript try/catch/finally Statement

3. Reactivate

Let’s say you deleted by mistake a master layer to your expressions, then they all are deactivated; even a Cmd+Z won’t bring them back to life. Oh yeah, you know what I am talking about, revealing all expressions to re-enable them one by one while lashing yourself and cursing the world you live in!

ActivateDisabledExpressions is a free script that will save your life; it will look for the disabled expressions and batch – reactivate them.

If you have a few bucks to spend, I highly recommend to Paul Tuersley’s ExpressEdit 2, a great script that can find disabled expressions, but also can be used as an expression library to save your codes, search for specified and batch apply expressions to selected layers.

Lesson08 – Delays and Loops

Learn how to create a looping delay / echo / cascade effect on your animation

REMINDER
If you are an absolute beginner, please start your learning by checking the essential resources below:
http://www.jjgifford.com/expressions/basics/index.html
https://helpx.adobe.com/after-effects/using/expression-basics.html
http://www.motionscript.com

1. Setup

  • Create a new Shape Layer, with a group including a path/shape and a color fill
  • Import the color swatches preset from previous lesson, and rename the layer to “colors”. Make sure no layer is selected in the timeline when importing the preset
  • Rename the group in the new Shape Layer to “01”
  • Add xpr_colorShapes preset from previous lesson to the Fill; colors are now linked to the name of the group and the color swatches. When duplicating the group, it creates a new instance using the next color.
  • Animate the position property of the Group (“01”)

2. Delay

  • Duplicate the Group (“01”) and delete the keyframes on the position property
  • Add an expression to Shape Layer> Group(“02”)> Transform> Position
  • Create a new variable to store the group name
var i = thisProperty.propertyGroup(2).name;
  • Create a new variable to store the reference Group (“01”) postion
var pos = thisProperty.propertyGroup(4).content(“01”).transform.position;

or

using the pickwhip to retrieve the path

  • Shift in time the position value
.valueAtTime(time)
Returns the value of a property at the specified time, in seconds.
pos.valueAtTime(time-(i-1))

This result will delay the second Group animation of 1 second. To change the delay influence, you can either directly add a mathematic operator to (i-1) or add an expression control for a more intuitive control over the delay

  • Route 1: mathematic operator
pos.valueAtTime(time-(i-1)*5/25)

Now the delay will only be of 5 frames (in a 25fps composition). Note that positive values will invert the delay, making the top layer coming first.

  • Route 2: expression controller; add a Effect> Expression Control> Slider Control
var delay = effect(“Slider Control”)(“Slider”);
pos.valueAtTime(time+(i-1)*delay)
  • Duplicate Group (“02”) as many times as you want and adjust Slider (“delay”) if you chose route 2

3. Built-in loop

This simpliest way to loop an animation is to use one of the loop built-in object

  • Reveal the set of keyframes on Shape Layer> Group (“01”)> Transform> Position
  • Without deleting the keyframes, add an expression to the Position property
loopIn/loopOut(type,keyframes)
use keyframes to loop on the specified interval

loopInDuration/loopOutDuration(type, duration)
use the inPoint/outPoint of the layer to loop on the specified duration

Most used types are cycle (default) and pingpong;
check built-in help for more

loopOut()

You don’t need to specify any parameter in the brackets to repeat the animation

  • Find the frame where you wish the loop to end and add a keyframe

4. Modulo loop

The built-in loop objects are most of the time enough, but they have limits; first animation needs to be most of the time precomposed, secondly, they can not coexist with other expression in a same block of code.

  • Delete the keyframes on Shape Layer> Group (“01”)> Transform> Position and replace them with a linear interpolation
linear(time, 0, 2,[-1080,0],[1080,0])

If you try to add a loop object on the next line, you will be prompted with an error message; loop object can not be added to a pre-existing block of code. But modulo (%) has no such limit, it is a basic mathematic operator that plays well with interpolations.

  • Edit the expression
linear(time%2, 0, 2,[-1080,0],[1080,0])

Every 2 seconds, the animation will loop; it would work perfectly if we did not have to take into consideration the delay. You could either adjust the loop duration manually to a value greater than the endFrame value, or create a set of new variables to get the exact delay duration.

  • Edit the expression
var delay = Math.abs(effect(“Slider Control”)(“Slider”));
var i = (thisProperty.propertyGroup(3).numProperties-1);
linear(time%(2+delay*i), 0, 2,[-1080,0],[1080,0])

by adding the delay * number of iterations, the loop matches exactly the animation length.

  • To smoothen in/out the animation, change linear to ease
ease(time, startFrame, endFrame, value1, value2)
generates a smooth interpolation
ease(time%(2+delay*i), 0, 2,[-1080,0],[1080,0])

Unfortunatety, velocity values are not accessible through expression; to get more control on the velocity, check out Ease and Wizz by Ian Haigh, a script with a nice collection of expressions that generate Expo, Circ, Quint, Quart, Quad, Sine eases, and more!

DON’T FORGET
build your own presets collection to speed up your workflow
Click icon below to download presets (rename .key to .zip after download)
download

 

Lesson07 – Color Palette / Swatches

Learn how to create a color palette/swatches to make a master control for your compositions colors

REMINDER
If you are an absolute beginner, please start your learning by checking the essential resources below:
http://www.jjgifford.com/expressions/basics/index.html
https://helpx.adobe.com/after-effects/using/expression-basics.html
http://www.motionscript.com

1. Color Swatches

  • Create a new Shape Layer and rename it to “colors”
  • Add an empty Group and rename it to “swatches”
  • Add a Group to Shape Layer(“colors”)> group(“swatches”) and rename it to “01
  • Add a Rectangle Path and a Color Fill to Shape Layer(“colors”)> group(“swatches”)> group(“01”)

Each rectangle will be a color swatch for the composition (and pre-comps too).

  • To automatically align duplicate of the swatch, add an expression to Shape Layer(“colors”)> group(“swatches”)> group(“01”)> Transform> Position
.propertyIndex
retrieves the index of the targeted property.
Note that Indexes increment as you duplicate them,
while numerical names keep the same value.
var x=content(“swatches”).content(“01”).content(“Rectangle Path 1”).size[0]*(thisProperty.propertyGroup(2).propertyIndex-1);
[x, value[1]]

Use the pickwhip to retrieve the path to the Rectange Path Size. With propertyGroup, get the index of the group and use shift the position of each (Check lesson04 to review propertyGroup argument)

  • To automatically position the color palette on the left corner, add an expression to Shape Layer(“colors”)> group(“swatches”)> Transform> Position
width gets the composition width
height gets the composition height
[-width/2,height/2]
  • Then on the Anchor Point, add another expression
var s=content(“swatches”).content(“01”).content(“Rectangle Path 1”).size[0];
[-s/2,s/2]

Use the pickwhip to retrieve the path to the Rectange Path Size.

Now duplicate the group(“01”) as many times as you want to create more swatches.
By changing the Shape Layer(“colors”)> group(“swatches”)> Transform> Scale , you can resize the color palette.

By making it a Guide Layer, while still showing up in the composition, I will be ignored when rendering without having to hide it.
Changes the colors to your client’s graphic guidelines, or use Window> Extensions> Adobe color themes to pick pre-made color schemes.

2. Link colors

Now each time you create a new Shape Layer, add a color correction filter or create a Solid Layer, you can link it to the corresponding color.

  • Create a new Polygon Shape Layer by click-holding the shape layer icon in the tool bar and polygon tool in the drop-down menu
  • Navigate down to the Fill property and rename it to “01”
  • Add an expression to the Fill Color
var select = thisProperty.propertyGroup(1).name;
thisComp.layer(“colors”).content(“swatches”).content(select).content(“Fill 1”).color

Use the pickwhip to retrieve the path to the 1st swatch fill color in Shape Layer(“colors”)> group(“swatches”)> group(“01”)> Fill 1> Color , then change (“01”) to (select)

By changing the name of the shape group to “02”,”03″,”04″… you’ll be adjusting the color.
Save the expression as a preset to easily apply the expression to all you colors.

For filters using colors, remember to rename the filter’s name instead.
You can also prefer to manually adjsut the expression rather than using the filters/layers/groups names, that is your call.

3. Auto-cyle colors

Let’s say we plan on creating a delay with multiples groups in a shape layer, and that we would like to have the instances to each have a different color.

  • First we need to know how many swatches in the palette
.numProperties
returns how many properties populates the group
var count = thisComp.layer(“colors”).content(“swatches”).content(“01”).propertyGroup(1).numProperties;
var select = thisProperty.propertyGroup(3).name;

Note that because we will duplicate the whole group, the color index this time is linked to the group name at .propertyGroup(3)

Modulo (value % threshold)
is a division reminder;
you can understand it as a loop operator:
each time a value reaches the threshold,
it will start again from 0.
0%5 = 5%5 = 10%5 = 0
1%5 = 6%5 = 11%5 = 1

4%5 = 8%5 = 14%5 = 5
  • To loop the colors, enter the result
thisComp.layer(“colors”).content(“swatches”)­.content(select%count+1).content(“Fill 1”).color

Modulo starts from zero but the color palette range starts at one, hence +1

DON’T FORGET

build your own presets collection to speed up your workflow

Click icon below to download presets (rename .key to .zip after download) download