Skip to main content
Known Participant
February 29, 2020
Question

Erase Same Area For 40 Layers

  • February 29, 2020
  • 4 replies
  • 342 views

I have 40 layers with an object in the corner for all of them. It does not move. Nothing in the frames moves except a part of a different corner.

 

Is there a way I can erase a non-moving object/area for all 40 frames without doing them 1 by 1 by hand? A mask? I created a mask, but have tried ALT and/or Ctrl and drag to copy it to the next layer but not working.

 

Thanks.

This topic has been closed for replies.

4 replies

Stephen Marsh
Community Expert
Community Expert
February 29, 2020

And another:

 

// https://forums.adobe.com/message/8854612#8854612
// What it does, is apply a selected action to each of the selected layers individually.
// So for example, if you had 50 layers that you wanted to each rotate by 90 degrees in place, 
// you'd record a rotate-by-90-degrees action, select all the layers you want to apply it to and run the script with the action selected.

#target photoshop  
  
  
var scriptName = "NinjaScript IterateActionLayers";  
var scriptVersion = "0002";  
  
  
function cID (inVal) { return charIDToTypeID(inVal);}  
function sID (inVal) { return stringIDToTypeID(inVal);}  
  
  
var currentActionSets = getActionSets();  
  
  
main();  
function main()  
{  
    app.bringToFront();  
    optionsDialog();  
}  
  
  
function optionsDialog()  
{  
    var ButtonWidth = 100;  
      
  OpenOptionsDialog = new Window("dialog", scriptName + " v" + scriptVersion);  
  
  OpenOptionsDialog.orientation = 'column';  
  OpenOptionsDialog.alignChildren = 'left';  
  
  
    mainGroup = OpenOptionsDialog.add("group");  
    mainGroup.orientation = 'column';  
    mainGroup.alignChildren = 'left';  
    mainGroup.alignment = 'left';       
  
  
    var actionSetGroup = mainGroup.add("group");  
    actionSetGroup.orientation = 'row';  
    actionSetGroup.add("statictext",undefined, "ActionSet: ")  
    var DDActionSet = actionSetGroup.add("dropdownlist",undefined, "")  
    DDActionSet.preferredSize.width = 150;  
         
    for (var i = 0; i < currentActionSets.length; i++)  
    {  
            DDActionSet.add("item", currentActionSets[i]);  
    }  
    DDActionSet.selection = 0;  
         
         
    var actionGroup = mainGroup.add("group");  
    actionGroup.orientation = 'row';  
    actionGroup.add("statictext",undefined, "Action:      ")  
    DDActions = actionGroup.add("dropdownlist",undefined, "")  
    DDActions.preferredSize.width = 150;  
      
    function populateDDActions (inSet)  
    {  
        DDActions.removeAll();  
          
        for (var i = 0; i < currentActionSets[inSet].actions.length; i++)  
        {  
            DDActions.add("item", currentActionSets[inSet].actions[i]);  
        }  
        DDActions.selection = 0;  
    }  
  
  
    DDActionSet.onChange = function()  
    {  
        populateDDActions(DDActionSet.selection.index);  
    }  
    DDActionSet.onChange();  
      
    mainGroup.add("statictext", undefined, "");  
       
    ButtonGroup = mainGroup.add("group");  
    ButtonGroup.orientation = 'row';  
    ButtonGroup.alignChildren = 'center';  
    ButtonGroup.alignment = 'top';       
  
  
              
    buttonRun= ButtonGroup.add("button",undefined, "Run")  
    buttonRun.preferredSize.width = ButtonWidth;  
    buttonRun.onClick = function()  
   {  
       var SelectedLayers = getSelectedLayers();  
         
        for (var i = 0; i < SelectedLayers.length; i++)  
        {  
            activeDocument.activeLayer = SelectedLayers[i];  
            doAction(DDActions.selection.text, DDActionSet.selection.text);  
              
        }  
        OpenOptionsDialog.close()  
    }  
      
    buttonClose= ButtonGroup.add("button",undefined, "Exit")  
    buttonClose.preferredSize.width = ButtonWidth;  
    buttonClose.onClick = function() {OpenOptionsDialog.close()}         
  
  
    //Show window  
  OpenOptionsDialog.center();  
  var result = OpenOptionsDialog.show();  
}  
  
  
function getActionSets()   
{    
  var i = 1;    
  var sets = [];    
  while (true) {    
    var ref = new ActionReference();    
    ref.putIndex(cID("ASet"), i);    
    var desc;    
    var lvl = $.level;    
    $.level = 0;    
    try {    
      desc = executeActionGet(ref);    
    } catch (e) {    
      break;    // all done    
    } finally {    
      $.level = lvl;    
    }    
    if (desc.hasKey(cID("Nm  "))) {    
      var set = {};    
      set.index = i;    
      set.name = desc.getString(cID("Nm  "));    
      set.toString = function() { return this.name; };    
      set.count = desc.getInteger(cID("NmbC"));    
      set.actions = [];    
      for (var j = 1; j <= set.count; j++) {    
        var ref = new ActionReference();    
        ref.putIndex(cID('Actn'), j);    
        ref.putIndex(cID('ASet'), set.index);    
        var adesc = executeActionGet(ref);    
        var actName = adesc.getString(cID('Nm  '));    
        set.actions.push(actName);    
      }    
      sets.push(set);    
    }    
    i++;    
  }    
  return sets;    
};    
  
  
function getSelectedLayers()  
{  
  var resultLayers=new Array();  
  try{  
    var descGrp = new ActionDescriptor();  
    var refGrp = new ActionReference();  
    refGrp.putEnumerated(cID( "Lyr " ),cID( "Ordn" ),cID( "Trgt" ));  
    descGrp.putReference(cID( "null" ), refGrp );  
    executeAction( sID( "groupLayersEvent" ), descGrp, DialogModes.NO );  
    for (var ix=0;ix<app.activeDocument.activeLayer.layers.length;ix++){resultLayers.push(app.activeDocument.activeLayer.layers[ix])}  
    var desc5 = new ActionDescriptor();  
    var ref2 = new ActionReference();  
    ref2.putEnumerated( cID( "HstS" ), cID( "Ordn" ), cID( "Prvs" ) );  
    desc5.putReference( cID( "null" ), ref2 );  
    executeAction( cID( "slct" ), desc5, DialogModes.NO );  
  } catch (err) { }  
  return resultLayers;  
}     
Stephen Marsh
Community Expert
Community Expert
February 29, 2020
Stephen Marsh
Community Expert
Community Expert
February 29, 2020

Another variation on the theme, this one also processes a Background layer.

 

//forums.adobe.com/message/8895266#8895266
//forums.adobe.com/message/8895401#8895401

var ActionName = "Run";
var ActionSet = "Filler.atn";

if (!documents.length) {
   alert('There are no documents open.', 'No Document');
} else {
   processArtLayers(activeDocument);
}

function processArtLayers(obj) {
   for (var i = obj.artLayers.length - 1; 0 <= i; i--) {
      activeDocument.activeLayer = obj.artLayers[i];
      doAction(ActionName, ActionSet);
   }
   for (var i = obj.layerSets.length - 1; 0 <= i; i--) {
      processArtLayers(obj.layerSets[i]);
   } // Process Layer Set Layers  
}
Stephen Marsh
Community Expert
Community Expert
February 29, 2020

Create what you need to do in an action (select fill, select clear, select layer mask etc).

 

The following script will iterate the playback of an action over all layers except the background layer (there is no checking for layers such as fill layers, adjustment layers etc - this basic script assumes that all layers are standard raster layers).

 

On line 11, replace Filler.atn with your action set (folder) name and replace Run with your action name.

 

 

#target photoshop
if (app.documents.length > 0) {
   function main() {
      var docRef = activeDocument;
      var layerNum = docRef.layers.length;
      for (var i = 0; i < layerNum; i++) {
         docRef.activeLayer = docRef.layers[i];
         if (!docRef.activeLayer.isBackgroundLayer) {
            try {
               // Change the action and action set name
               app.doAction('Run', 'Filler.atn');
            } catch (e) {}
         }
      }
   }
   app.activeDocument.suspendHistory("Undo the script!", "main()");
} else {
   alert('There are no open files!')
}