Advertisement
NullChips

Mass Rename script for AE

Nov 1st, 2016 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //General variables.
  2. var theComp= app.project.activeItem;
  3. var selectedLayers = theComp.selectedLayers;
  4.  
  5. //Starts mass-rename function.
  6. massRename();
  7.  
  8. //Start of mass-rename function:
  9. function massRename(){
  10.  
  11.     app.beginUndoGroup("layer rename");
  12.    
  13.     //Checks that the current item is a composition.
  14.    if (!theComp || !(theComp instanceof CompItem)){
  15.         alert("No composition is selected. Please select a composition and try again.");
  16.         return;
  17.     }
  18.  
  19.     //Checks that some layers are selected and sets the default name in the prompt to the bottom layer selected.
  20.     var originalName = "placeholder";
  21.     if(theComp.selectedLayers.length < 1){
  22.         alert("No layers are selected.");
  23.         return;
  24.     }else{
  25.         originalName = theComp.selectedLayers[0].name;
  26.     }
  27.    
  28.     //Gets input for a new name from the user and checks that something actually has been inputted.
  29.     var newName = prompt("Please enter a name", originalName);
  30.     if(newName.length < 1){
  31.         alert("No new name has been inputted.");
  32.         return;
  33.     }
  34.  
  35.     //Renames all the layers.
  36.     for(var i =0; i < theComp.selectedLayers.length;i++){
  37.         var name = newName + " " + String(i+1);
  38.         var currLayer = theComp.selectedLayers[i];
  39.         try{currLayer.source.name = name;}catch(error){ $.writeln( "The layer has no source."); }
  40.         currLayer.name = name;
  41.     }
  42.  
  43.     app.endUndoGroup();
  44.    
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement