• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Apply Layer Mask to Numerous Layers (without grouping)

Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Hi all,

For reasons that I don't wish to bore people with, I am trying to apply the same layer mask over many layers - far too many to 'alt-drag'. Then later disable/delete them.

 

I've tried several work arounds, but not much luck. I can't select all layers and paste, or 'add layer mask' to multiple layers. The best I can do is load selcetion, but it wont cut all layers. 

I tried to do an action, but I haven't done it in years. I can action it layer at a time, but if I work over a few layers, I get the - The Command "Make" is not currently available. 

I'm an intemittent user, so things may have changed for me. 

Thanks for your help.

 

G

TOPICS
Actions and scripting

Views

3.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 30, 2020 Apr 30, 2020
// apply active selection as layer masks to selected layers;
// 2020, use it at your own risk;
if(app.documents.length != 0) {
applyLayerMasksToLayers();
};
////// apply layer masks to selected layers //////
function applyLayerMasksToLayers(){
var theLayers = getSelectedLayersIdx();
var selection = hasSelection();
if (selection == true) {app.activeDocument.selection.deselect()};
for(i = 0; i < theLayers.length; i++){
selectLayerByIndex(theLayers[i], false);
// remove existing mask;
if (hasLayerM
...

Votes

Translate

Translate
Adobe
Participant ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

I thought I did?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

So try please again if that didn't work in Jul 03, 2021 & in the other thread.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

"The command "Make" is not currently available".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

Running which code you're getting this alert?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

sTT = stringIDToTypeID; (dsc = new ActionDescriptor())
.putClass(sTT('new'), chnnl = sTT('channel')); (ref = new ActionReference())
.putEnumerated(chnnl, chnnl, sTT('mask')), dsc.putReference(sTT('at'), ref)
dsc.putEnumerated(sTT('using'), sTT('userMaskEnabled'), sTT('hideAll'))
executeAction(sTT('make'), dsc)

 

I try to add Black mask to multiple selected layers.

Should I add this to the script above?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

To do it for only selected layers change 'RvlA' to 'HdAl' in below line of c.pfaffenbichler code:

 

else {makeLayerMask('RvlA')};

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

Works!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 06, 2021 Jul 06, 2021

Copy link to clipboard

Copied

Encountered an issue using this method. (As c.pfaffenbichler says 2020 use at you own risk).

Layers above selected layers with new mask in layer hierachy loose functionality after using this script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2021 Jul 06, 2021

Copy link to clipboard

Copied

Please explain and post screenshots to illustrate the problem. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 06, 2021 Jul 06, 2021

Copy link to clipboard

Copied

I am sorry, my bad. I can't manage to recreate it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 06, 2021 Jul 06, 2021

Copy link to clipboard

Copied

So there is no problem about it for you anymore?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 06, 2021 Jul 06, 2021

Copy link to clipboard

Copied

LATEST

No, not a problem. Thought it was this script but I was wrong.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

You could also place the layers inside a clipping group, it is not exactly a layer group...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Hi,

I should have added, say I'm doing a profile photo of a car, in 50 plus scenerios, I wish to align the cars, but not let other things in the frame distract it, clouds, treees, etc.

When I did it as a group, I felt that when I did it as a group mask, it the intelligence was still influenced by the whole picture, not the isolated part (masked car). I'm not sure with clipping group would act any different, or enable me to bring back the BGs (I'll google clipping groups).

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 06, 2020 May 06, 2020

Copy link to clipboard

Copied

Photoshop is a visual tool, however, the forum only has text descriptions to go by, which can be hard. If a picture is worth a thousand words, wouldn't a screenshot of your layers, or samples of the image layer stack elements be helpful?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2020 May 08, 2020

Copy link to clipboard

Copied

The following script may not be perfect, however, it will get the job done.  It is more of a "general purpose" script to apply "something" to all top-level layers and layer sets and also to layers within layer sets. One could obviously swap out the function to run an action with "use-specific" script code so that there is no dependency on having an action. I decided to use an action for the "use-specific" processing in this topic as this makes the script accessible and modular.

 

The script does all the heavy lifting, however, it requires the following to be set before running the script:

 

1) The mask channel should be copied to the clipboard

 

2) An action that applies the clipboard content as a layer mask with an action set name of Copied Channel as Mask with a referenced action name of Run

 

mask-atn.png

 

Link to action:

Copied Channel as Mask.atn

 

 

 

/* 

Apply layer mask action to all layer sets and layers.jsx

In reply to:
Apply Layer Mask to Numerous Layers (without grouping)
https://community.adobe.com/t5/photoshop/apply-layer-mask-to-numerous-layers-without-grouping/td-p/11093194

The script does all the heavy lifting, however, it requires the following to be set before running the script:

1) The mask channel should be copied to the clipboard
2) An action that applies the clipboard content as a layer mask with an action set name of 'Copied Channel as Mask' with a referenced action name of 'Run'

Based on:
https://forums.adobe.com/message/8895266#8895266
https://forums.adobe.com/message/8895401#8895401

*/

function main() {

    if (!documents.length) {
        alert('There are no documents open!');
    } else {
        processAllLayersAndSets(app.activeDocument);
    }

    function processAllLayersAndSets(obj) {

        // Process all layers and layer sets
        // Change the following 2 entries of "obj.layers" to "obj.artLayers" to exclude layer sets
        for (var al = obj.layers.length - 1; 0 <= al; al--) {
            app.activeDocument.activeLayer = obj.layers[al];

            // Start function call to run action
            runAction();
            // Finish function call to run action

        }

        // Process Layer Set Layers 
        for (var ls = obj.layerSets.length - 1; 0 <= ls; ls--) {
            processAllLayersAndSets(obj.layerSets[ls]);

            // Start function call to run action
            runAction();
            // Finish function call to run action

        }
    }

    function runAction() {
        app.doAction('Run', 'Copied Channel as Mask'); // Action and action set name
    }
}

activeDocument.suspendHistory('Process Layers & Sets', 'main()');

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

Another option:

 

Apply Action To Layers.jsx

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

And this one:

 

// https://forums.adobe.com/thread/2285411
// Change Line 15 for the action and parent action set
#target photoshop  
if (app.documents.length > 0) {  
var myDocument = app.activeDocument;  
myDocument.suspendHistory("operation", "main(myDocument)");  
};  
////////////////////////////////////  
function main () {  
var theLayers = getSelectedLayersIdx();  
// do stuff;  
// reselect layers;  
for (var p = 0; p < theLayers.length; p++) {  
  selectLayerByIndex(theLayers[p], false);  
  app.doAction('Invert Action', 'Invert Set'); // Define the action to play and the action set 
  };  
};  
//   
function selectLayerByIndex(index,add){  
add = undefined ? add = false:add  
var ref = new ActionReference();  
    ref.putIndex(charIDToTypeID("Lyr "), index);  
    var desc = new ActionDescriptor();  
    desc.putReference(charIDToTypeID("null"), ref );  
       if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );  
      desc.putBoolean( charIDToTypeID( "MkVs" ), false );  
   try{  
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );  
}catch(e){  
alert(e.message);  
}  
};  
////// by paul mr;  
function getSelectedLayersIdx(){  
      var selectedLayers = new Array;  
      var ref = new ActionReference();  
      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );  
      var desc = executeActionGet(ref);  
      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){  
         desc = desc.getList( stringIDToTypeID( 'targetLayers' ));  
          var c = desc.count  
          var selectedLayers = new Array();  
          for(var i=0;i<c;i++){  
            try{  
               activeDocument.backgroundLayer;  
               selectedLayers.push(  desc.getReference( i ).getIndex() );  
            }catch(e){  
               selectedLayers.push(  desc.getReference( i ).getIndex()+1 );  
            }  
          }  
       }else{  
         var ref = new ActionReference();  
         ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));  
         ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );  
         try{  
            activeDocument.backgroundLayer;  
            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);  
         }catch(e){  
            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));  
         }  
      }  
      return selectedLayers;  
};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

This works perfect for what I need, and applies my action on selected layers.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

And this one:

 

 

// https://forums.adobe.com/message/8895442#8895442
// Loop or iterate an action to multiple layers
// You need to edit the code to include the name of your action that you created (line 26) and the name of the group folder that the action is in (line 28)
#target photoshop  
  
var doc = app.activeDocument;  
var layerVisble  
  
doc.activeLayer = doc.layers[0];  
  
for(var i=0;i<doc.layers.length;i++){  
    doc.activeLayer = doc.layers[i];  
    layerVisible = doc.activeLayer.visible;  
    doc.activeLayer.visible = true;  
    spot ();  
    doc.activeLayer.visible = layerVisible;  
    }  
alert('done');  
  
function spot(){  
    var idPly = charIDToTypeID( "Ply " );  
    var desc2 = new ActionDescriptor();  
    var idnull = charIDToTypeID( "null" );  
    var ref1 = new ActionReference();  
    var idActn = charIDToTypeID( "Actn" );  
    ref1.putName( idActn, "TEMP" );  // Name of action  
    var idASet = charIDToTypeID( "ASet" );  
    ref1.putName( idASet, "TEMP" ); // Action set name  
    desc2.putReference( idnull, ref1 );  
executeAction( idPly, desc2, DialogModes.NO );  
}

 

Or perhaps this one:

 

// https://forums.adobe.com/message/8895266#8895266
// https://forums.adobe.com/message/8895401#8895401
var ActionName = "RandonFillColor";  
var ActionSet = "temp";  
  
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  
}  

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

Thank you, Stephen!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines