Working on a project that may have many hundreds of layers, and while many will have the same animations with time offsets etc I need to build it as an adjustable template.
Effectively I'm looking for a way to have many layers using the same expression from a single control layer so that if I want to make modifications to the expression I don't have to go through 100+ layers and re-paste the expression.
Ideal scenario would be to have an "Master Expressions" layer which has many properties with the applied expressions and then on all my other layers have them pull the expression code from the appropriate "Master Expressions" property. This way when I update the code in the "Master Expressions" it is applied globally across all linked layers.
I've attempted to use a Text Layer and input my expression in the "Source Text" parameter, but I have not found a way to pull the full text as applied expression for another layer.
Say you have a text layer named "expression" with this text:
freq = 1;
amp = 100;
Then you could have this expression in another layer:
txt = thisComp.layer("expression").text.sourceText.value;
You got me 99% there! One thing I found I needed to add around the expression in the text layer is triple quotes around the whole expression so that it behaved properly.
freq = 1;
amp = 100;
I tried your trick (and it worked! Thanks!) but I would like my text layers to be stored in a different composition. I typed in:
txt = comp(exp).layer("expression pos").text.sourceText.value;
but all i get is an error stating that "the property or method named 'exp' in Class 'global' is missing or does not exist."
What is weird is that it obviously finds both my composition, and my text layers, as the expression changes when I rename said layers. For instance, if I were to rename "expression pos" in the composition "exp" to "layerboy", the expression would change to:
txt = comp(exp).layer("layerboy").text.sourceText.value;
Any ideas...? By the way, I'm way new at this. Appreciate your help so far.
if "exp" is the name of the composition, then it would be like this:
txt = comp("exp").layer("expression pos").text.sourceText.value;
Thank you so much!
I've got a very similar situation, but am getting am getting the error, "undefined value used in expression (could be an out of range array subscript?)...
I have a comp called "Expressions". Within that comp, I have a layer called "Truck Wheel Position". In that null layer's position property, I've got the expression written as follows:
freq = 6;
amp = 3;
(The purpose here is to wiggle the position on the "y" value only, which works on the null layer with the expression.
In a separate composition, I've got several shape layers with the expression written as follows:
pos = comp("Expressions").layer("Truck Wheel Position").transform.value;
This returns the error mentioned above...
Any ideas on how expression could be fixed?
Ah, that actually helped a lot! I was misunderstanding the use of the examples above, but I've got it working now.
I was attempting to set the expression within the desired property of my "master expression layer", but I now realize that we're simply copying the literal text of a text layer into our desired layer's property expression.
Also note that with the new json features of After Effects, you can share expressions code much cleaner. See this tutorial: