Hey all, I'm building MOGRTs more and more, and I often use a ton of expressions as I find it can really help speed up the animation workflow. I'd like to ask for some kind of global object to use in expressions. This would make expressions many times more efficient and lightweight to run. It could be a global function or class, but I think an object would be preferable. An example from a recent project is where there are many moving elements that are adjustable via the EGP (essential graphics panel). Depending on the user inputs in EGP, the layers move differently or at different times. Due to the way AFX expressions work, I had to write a script and then copy and modify it for every single layer, and in that script there was a lot of duplication in the script. When there was an amendment to the script, I had to edit every instance of that script and account for any unique properties of that layer. Imagine then, I have a global object that is iniated at begining of project and is accessible to every layer: const global = {}; Using this, I can create a single layer that runs a streamlined, lightweight version of the expressions and outputs it to global like this: t = thisComp.layer("controls").effect("type")("Menu");
s = thisComp.layer("controls").effect("size")("Slider");
d = thisComp.layer("controls").effect("duration")("Slider");
// Calculate how the inputs affect the properties
if (f == 1) {
output1 = linear(time, 0, d, 0, s);
output2 = linear(time, d, 0, s, 0);
} else if (f == 2) {
output1 = linear(time, 0, d, 50, s);
output2 = linear(time, d, 0, s, 50);
} else {
output1 = linear(time, 0, (d*2), 0, s);
output2 = linear(time, d, 0, (s*2), 0);
}
s = thisComp.layer("style").text.sourceText.style;
s = s.setText(val)
global = {
"layer1" : {
"position" : [0,output1],
"opacity" : linear(time, 0, d, 0, output1),
},
"layer2" : {
"position" : [0,output1],
"opacity" : linear(time, 0, d, 0, output1-output2),
},
"layer3" : {
"position" : [0,output1],
"opacity" : linear(time, 0, d, 0, output1+output2),
}
} Consider the above script, I can do a round of calculations and assign those to the global variable, and then in layer1 I can simply call global["layer1"].position in an expression in the position property. This saves recalculating everything for every layer, which is what I currently have to do. I did try to find a workaround: I created a text layer, set it up like so, and set the text output to: "JSON.encode(global)". I then read the text layer with other layers and used JSON.parse() to read it in. It worked a bit but it was buggy and clearly didn't like it. I'd find a global object that could be used in expressions very useful and valuable in AFX please!
... View more