After Effects timesaving: Expressions
I admit, I am not the most advanced user of expressions but having the right piece of code can really speed up your workflow. This article is not intended to be a guide to writing expressions, more like a nudge in the right direction for understanding what they can do. Even with a limited knowledge of how to use them you can set up effective timesaving expressions. I use them most for saving time when setting up a project that I know is going to be edited and duplicated a lot, while keeping core components.
One example of this is a job I did recently explaining the Expedia Affiliate Network. The client wanted a style that combined footage and information interacting with each other often featuring boxes and lines connecting. As we don't have the Plexus plugin for After Effects, I had to find another way. Before anybody started on the animation I set up a series of nulls in 3D space that were linked to the end points of a beam effect.
The problem was that the beam effect could only be positioned in 2D space. When the expression is just pickwhipped to the null positions it becomes offset when they are moved along the Z plane - this is because they are only referencing the X and Y coordinates, not the Z. So I needed to find a way to take the 3D coordinates of the null and convert them to the 2D coordinates that you can see in the viewport.
Luckily, there is a handy expression that does just this. Set up the comp with two nulls and turn their 3D switches on (named Null_main, Null_01), and a comp-sized solid with the beam effect applied. You will need to alter the settings of the beam slightly to get the look you want. I set the inside and outside colour to white, and set the Length to 100%
Option/Alt-click on the stopwatch for the starting point of the beam to bring up the expression editor for the property, Once you have dragged the pickwhip from the starting point of the beam to your first null, it will add the following code: "thisComp.layer("Null_main")" - you need to manually add on the end ".toComp([0,0,0])" to end up with the following expression:
Copy and paste this code into the Ending Point property of the same beam layer, and just change the code to reference the second null you created - thisComp.layer("null_01").toComp([0,0,0]) and now you can either move and rotate the camera, or move the nulls to mimic the effect that it is moving in 3D space. I placed the content that needed to be at the end of the lines on the null (copy and paste the position property of a null into that of a composition for your content to get the correct starting position) and parented this composition to the same null. This technique can be repeated for as many points as you like.
This .toComp expression can solve many problems, including for Trapcode Shine. Anybody who has tried to use this in a 3D comp will know how frustrating it is to have to manually keyframe the source point when really you want it to just track a point in 3D space.
Another way I used altered pickwhip expressions is when using Trapcode Particular. One way of moving the emitter point in 3D space is to change the Emitter type to "Light" and creating a light called "Emitter" - this is fine but what if you need more than one emitter in a comp for multiple instances of particular? you can link it to a null will just a couple of extra steps, and then use as many nulls as you like.
Change the emitter type to "Point" and Option/Alt-click the "Position XY" property stopwatch within the effect (NOT the solid's position property, this layer is just a holder for the effect and should stay 2D and static throughout) and drag the pickwhip to a new 3D null layer's position property.
This creates the same problem that we had with the beam effect, it is fine in 2D space but not when the null is moved on the Z-plane things get messy. To solve this you just need to do the same for the particular layers "Position Z" property, but this time drag the pickwhip onto just the 3rd number of of the nulls position property (the coordinates read (x,y,z). This tells the particular emitter that its Z position should be the same as the Z position of the null, along with the X and Y.
There is a fantastic resource called motionscript where you can learn expressions. The site's creator, Dan Ebbert, has breakdowns of simple and more complex expressions which means that if you want to just copy a simple expression, you can do, but you can also read his breakdown of what commands do what in an expression. After heading back to this site a few times you will understand how you can combine and modify the code provided.
Cameras and Nulls
Perhaps not so much an immediate time saving tip, but a good way of working that avoids necessary complications when using 3D cameras in After Effects. Simply create a new null object and camera and select the 3D layer switch for the null object. Parent the camera to the null object (select the null object layer from the dropdown box in the 'parent' column of the camera).
Any keyframes can now be made using the null object, the main advantages being that the camera now rotates around the null and you have a visual device in your comp window to move the camera with. This will mean that your comp and camera keyframes are much tidier.
A lot of people know about about adding a wiggle expression, or random movements to properties - for example if you wanted to wiggle the position you would open the expression editor for the position (alt-click the position stopwatch) and type "wiggle(2,25)" in this example the position would move with a threshold of 25 pixels above or below the current position twice a second. This technique can be used for any value or property with a numeric value.
What if you want to ease a wiggle up or down, to make an object judder only for a second or two? You can attach the wiggle expression to a slider where you can keyframe the second value in the expression, the range of the wiggle.
Create the wiggle expression in the usual way, then make a new null object and rename it "wiggle_slider". Search for the effect "slider control", add it to the null and expand the effect in the layers panel. There's a handy tip that may come in useful when using other expressions that link to other layers, highlight just the value in the expression that you want to change, in this case the second value - wiggle(2,25). grab the pickwhip of this property and drag it to the slider property on your newly created "wiggle_slider" layer.
You will notice that the expression now changes to include a reference to the slider and now any value that the slider shows is the range of the wiggle on the original layer. Set this back to 25 (as the slider will automatically be set to 0) and you can keyframe the slider to adjust the wiggle as much as you like!
Be aware that this must be applied to the second - the range value, as if it is applied to the frequency there will be jumps in the animation that cannot be avoided.
Posted: Wed 4th Apr 2012