You can't put the expression on a null object, but you can use a text layer.
Following @bobtiki's eval()
tip I tried using the source text of a text layer and running eval()
on it. Initially I had no success, I was getting an "object of type TextProperty found where a Number, Array or Property is needed" error. But if I put something like a number on its own in the text layer and treated the source text like an array I could get it, I just wasn't able to access a whole string.
I was about to give up, then I remembered from doing extendscript scripting that you get the raw value of an AE property object using the javascript property .value
*.
So after a bit of fiddling around with quotes and escaping (neither are needed, thank heavens) I got it to work.
TL;DR: Here is how you reference an expression that is written in a text layer's source, without having to save external files:
var theExpression = thisComp.layer("your text layer").text.sourceText.value;
eval(theExpression);
And then you write the expression into the text layer, in this case called "your text layer". This is really cool! It even updates in real time as you're typing the expression!
Here's a comp with the position of the cyan layers being driven by the expression you see on the text layer. If I duplicate one of the cyan layers its position is calculated individually based on the random seed index
, and if I change the expression, they all update!
I'm stoked, this was the best question ever!
* this sentence sounds like gibberish I know. The problem is that AE layers' property's values are JavaScript objects, and as such they have JavaScript properties, and one of the AE property's value's JavaScript properties is the value
property which represents the raw value of the AE property. And the value of the AE source text property is an object which must include formatting and whatnot, and so it is different to the text.sourceText.value value. Confused?