-
Notifications
You must be signed in to change notification settings - Fork 56
/
changeAllNames.jsx
101 lines (83 loc) · 3.21 KB
/
changeAllNames.jsx
1
/**Snippet to change target name project-wise.*Comp names and layer names are going to be affected.*I believe there are going to be problems with expressions.*Though I'm not sure**CC-BY, Nik Ska, 2015*/var wrongName = "??";var targetName = "WATWAT";var howMuch = 0;var changeNames = this;changeNames.go = function(wrongName, targetName) { app.beginUndoGroup("Changeallnames"); //1. Disable all expressions changeNames.switchAllExpressions(false, wrongName, targetName); //2. Now change names for(var i = app.project.numItems; i > 0; i--){ var thisItem = app.project.item(i); if(thisItem.name == wrongName){ thisItem.name = targetName; howMuch++; } if(thisItem instanceof CompItem){ for(var c = thisItem.layers.length; c > 0; c--){ var thisLayer = thisItem.layers[c]; if(thisLayer.name == wrongName){ thisLayer.name = targetName; thisLayer.selected = true; thisItem.openInViewer(); howMuch++ } } } } //3. Enable all expressions changeNames.switchAllExpressions(true, '', ''); app.endUndoGroup(); alert("Changed " + String(howMuch) + " names");}changeNames.switchAllExpressions = function(enable, find, replace){ //if enabled == true, enables all expressions. disables otherwise for(var i = app.project.numItems; i > 0; i--){ var thisItem = app.project.item(i); if(thisItem instanceof CompItem){ for(var l = thisItem.layers.length; l > 0; l--){ var thisLayer = thisItem.layers[l]; changeNames.switchExpressions(thisLayer, enable, find, replace); } } }}changeNames.switchExpressions = function(layer, activate, find, replace){ function replaceAll(string, find, replace) { return string.replace(new RegExp(escapeRegExp(find), 'g'), replace); } var enableDisableExpressions = function(_prop, activate, find, replace){ for(var i=1; i<=_prop.numProperties; i++){ var curProp=_prop.property(i); if(curProp instanceof PropertyGroup || curProp instanceof MaskPropertyGroup){ enableDisableExpressions(curProp, activate, find, replace); } else if (curProp.canSetExpression == true){ try{ if(curProp.expressionEnabled == true && activate == false){ curProp.expressionEnabled = false;//выкл } if(curProp.expressionEnabled == false && activate == true){ curProp.expressionEnabled = true;//вкл } if(activate == false){ //replacing target text in expression //when we disable expression curProp.expression = replaceAll(curProp.expression, find, replace); } } catch(err){ null } } } } enableDisableExpressions(layer, activate, find, replace);}changeNames.go(wrongName, targetName);