Copy link to clipboard
Copied
I have a global function in an expression that takes a text layer and autosizes it to fit a box. The expression works when I add to render queue in the program. However, when I send a .jsx file to aerender.exe with the same params, the global function is ignored. Any ideas why this happens?
Setup:
comp: // textConstrainer
. text layer: // textConstrainer
. expression on sourceText: $.textConstrainer = function (whichLayer) { code }
comp: Foo
. text layer: sizeMe
. expression on sourceText: $.textConstrainer(thisLayer)
Copy link to clipboard
Copied
The text file containing the Global Function should be placed in the Comp(s) that you send for rendering outside of AE and this includes aerender.
Copy link to clipboard
Copied
If I have to put the code in every comp it would defeat my purpose for having a global expression.
The global function is below. I have 50 comps. Each comp is different animation and each animation has at least 1 text layer and a shape layer 'box'. This function tells the text layer to scale to fit inside the box. How would I be able to put this function in one place so its available to all comps? Right now it's in an expression on the sourcetext of an empty comp.
global is below and at this github gist. I'm surprised there's not a more robust code formater in text tools
$.textConstrainer = function (whichLayer) {
if (whichLayer.hasParent) {
foundComp = whichLayer.parent;
}
layerName = whichLayer.name;
if (layerName.slice(-2) == "t1") {
target_box = "box1";
} else if (layerName.slice(-2) == "t2") {
target_box = "box2";
} else if (layerName.slice(0, 3) == "box") {
return 0;
}
var targetLayer = thisLayer.sourceRectAtTime(time);
var targetLayerWidth = targetLayer.width;
var targetLayerHeight = targetLayer.height;
var boxLayer = thisComp.layer(target_box.toString()).sourceRectAtTime(time);
var boxLayerWidth = boxLayer.width;
var boxLayerHeight = boxLayer.height
var ratioWidth = boxLayerWidth / targetLayerWidth;
var ratioHeight = boxLayerHeight / targetLayerHeight;
if (ratioHeight > ratioWidth) {
return [ratioWidth * 100, ratioWidth * 100];
} else if (ratioHeight < ratioWidth) {
return [ratioHeight * 100, ratioHeight * 100];
} else {
return value;
}
}
$.textConstrainer(thisLayer);