I spend a fair amount of time working with expressions, mostly for linking properties to other layers and driving animation from fewer keyframes. (It can save time when I ultimately have to retime animations or reuse them in different ways.) One thing that’s always bothered my about expressions is not being able to share variables between properties. Sure there are workarounds like using expression controls, but in all honesty, I like clean code. It’s easier to set up circleRadius = this.effect("Width").slider; once and use circleRadius in all the expressions in that layer (or comp) instead of always retyping this.effect("Width").slider or pickwhipping each time I want to use it.

By using a local or global variable, it would reduce complexity in the expressions. It would also have the added benefit of being able to change one line of code and affecting everywhere that variable was used. Say, for example, I was referencing transform.position.key(3) in 20 places in my layer. If I wanted to now use key(1), or if I added a keyframe and what was key(3) is now key(4), I’d have to change all 20 of those expressions. With local/global variables, I could change one line and it would be done.

The tricky part is how this could be accomplished. Here’s an example of some recent expression sets I’ve written to drive two Beam effects based on the position of a shape layer.

This is a fairly uncomplicated example, but shows using the same values many times.

As I mentioned earlier, what if I added new keyframes to the beginning of the shaper layer. It would change all the key values and I’d have to dig in and change all the expressions. A workaround would be to create a new null, parent, and animate that1. But who likes workarounds?

What if instead there were an extra layer property called “Expression Variables”? This way, you could set up variables that can be used by any property in the layer using local, or the entire comp with global declarations.

Click for larger image.

In the end, it’s possible to work around all of this, but for anyone working extensively with expressions, it could save a lot of time and frustration.

  1. Or, since I’m really animating the shape transform, I could animate the position of the actual shape layer.