I want a script that changes all instances of thisComp to comp("currentCompName") inside all expressions of selected layers.
I drafted this, but somehow it doesn't work but doesn't give me an error either. Also, after running, there's nothing to 'undo.'
Can someone with a keener eye look at it and tell me where I am missing something?
Code: Select all
/**********
* NotThisComp
**********
* Filename: NotThisComp v1.0.jsx
* Written by: Redsandro - http://www.rednet.nl/en/
* Date: 2008/12/10
* Last updated: 2008/12/10
**********
*
* Description:
*
* Traverses selected layers for expressions that reference thisComp
* and change them to comp("compName") so the layer can sit in a parent
* composition.
*
**********/
clearOutput();
var myComp = app.project.activeItem;
if (myComp == null) {
alert("You need to select a layer first.");
}
else {
// Gather data
//var compName = "no name";
//compName = prompt("What name do you want to reference instead of thisComp()", compName));
var myLayers = myComp.selectedLayers;
var myCompName = myComp.name;
var newName = "comp("+myCompName+")";
// Check selected
if (myLayers.length < 1)
alert("You need to select some layers first!");
else {
app.beginUndoGroup("NotThisComp");
// Walk layers
for (var l=0; l<myLayers.length; l++) {
var myLayer = myLayers[l];
// Walk properties
for (var p=0; p<myLayer.length; p++) {
var prop = myLayer[p];
if (prop.canSetExpression == true) {
if (prop.expression.indexOf("thisComp"))
prop.expression = prop.expression.split("thisComp").join(newName);
}
// if (.expressionEnabled != true) something went wrong
}
}
app.endUndoGroup();
}
}