Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //General variables.
- var theComp= app.project.activeItem;
- var selectedLayers = theComp.selectedLayers;
- //Starts mass-rename function.
- massRename();
- //Start of mass-rename function:
- function massRename(){
- app.beginUndoGroup("layer rename");
- //Checks that the current item is a composition.
- if (!theComp || !(theComp instanceof CompItem)){
- alert("No composition is selected. Please select a composition and try again.");
- return;
- }
- //Checks that some layers are selected and sets the default name in the prompt to the bottom layer selected.
- var originalName = "placeholder";
- if(theComp.selectedLayers.length < 1){
- alert("No layers are selected.");
- return;
- }else{
- originalName = theComp.selectedLayers[0].name;
- }
- //Gets input for a new name from the user and checks that something actually has been inputted.
- var newName = prompt("Please enter a name", originalName);
- if(newName.length < 1){
- alert("No new name has been inputted.");
- return;
- }
- //Renames all the layers.
- for(var i =0; i < theComp.selectedLayers.length;i++){
- var name = newName + " " + String(i+1);
- var currLayer = theComp.selectedLayers[i];
- try{currLayer.source.name = name;}catch(error){ $.writeln( "The layer has no source."); }
- currLayer.name = name;
- }
- app.endUndoGroup();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement