Hey there,
This solution is not super straightforward, but also not that complicated. ESTK provides a handy little app.project.autoFixExpression(oldText, newText) command, that you can use to batch-fix expressions. This is the main thing you’re looking for.
The issue is, autoFixExpressions will only fix expressions that YOUR SCRIPT causes to break, not preexisting errors. So, in the script here’s what we do.
1. Make variables that have the names of the comps we need (the controller comp, the pre-comp, and the new comp).
2. Find these comps.
3. Copy controller from the controller (‘top’) comp, to the new comp.
4. Remove controller from top comp, thereby breaking the expression.
5. run .autoFixExpressions(topCompName, newCompName) to fix the expressions.
Here’s the script. Hope it helps!
(function fixExpressions(){
app.beginUndoGroup("Fix expressions.");
var proj = app.project
var topCompName = "Top Comp"; // comp where controller lives now.
var preCompName = "Pre-Comp"; // comp where expressions are (that break).
var newCompName = "Another Comp"; // comp you want the controller in.
// holders for comps.
var topComp,preComp,newComp;
// loop through project and get the comps.
for (var i = 1; i <= proj.numItems; ++i){
switch(proj.item(i).name){
case topCompName:
topComp = proj.item(i);
break;
case preCompName:
preComp = proj.item(i);
break;
case newCompName:
newComp = proj.item(i);
break;
default:
break;
}
}
// move controller
topComp.layer("Controller").copyToComp(newComp);
// delete from old comp.
topComp.layer("Controller").remove();
// fix expressions
proj.autoFixExpressions(topCompName,newCompName);
app.endUndoGroup();
})();
David Conklin
Motion Designer