Skip to content
Fabian Morón Zirfas edited this page Mar 24, 2017 · 1 revision
/**
 * rename all selected layers with a prompt
 *
 */
/* eslint no-alert: off */
/* global app, CompItem, alert, prompt */
function main() {
  app.beginUndoGroup('rename'); // so we can revert it
  var curComp = app.project.activeItem; // get the active item
  // do a check if the item is a comp
  if (!curComp || !(curComp instanceof CompItem)) {
    alert('this is not a comp');
    return;
  }
  // get a name from the user
  var name = prompt('Please enter a new name', 'new-name', 'Add a name');
  // do a check if the user entered something
  if(name.length === 0) {
    alert('no name provided');
    return;
  }
  // loop the selected layers
  for(var i = 0; i < curComp.selectedLayers.length; i++) {
    var layer = curComp.selectedLayers[i];
    layer.name = name + ' ' + i;
  }
  app.endUndoGroup();
}
main(); // call the function

Home

Clone this wiki locally