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, How to

Views

1.4K

Likes

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

Adobe Community Professional , 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...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Post your action? How does your action know which layers to add the layer mask to?

JJMack

Likes

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
Adobe Community Professional ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

I expect this would need a Script. 

How can the Layers that you need to apply the Layer Mask to be identified? 

Likes

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,

Yes, that's what I mean by being an intermittent user. I'm sure in the past I would end the action by selecting the next layer. 

I had a selection saved. I had a layer selected. 1, I created a new set, then a new action. 2, layer, layer mask, hide all. 3, load selection. 4, fill white. 5, deselect. 6, select next layer. 7, stop.

I'm sure it's gotten more complicated than that. Any advice to point me in the right direction would help. 

Cheers,


Likes

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
Adobe Community Professional ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

»I'm sure in the past I would end the action by selecting the next layer.«

Selecting the next Layer above or below can be done via Keyboard Shortcut and I think it should record in an Action. 

Screenshot 2020-04-30 at 14.04.43.png

 

»I had a selection saved. I had a layer selected. 1, I created a new set, then a new action. 2, layer, layer mask, hide all. 3, load selection. 4, fill white. 5, deselect. 6, select next layer. 7, stop.«

I think you should provide the atn-file or post a screenshot of the expanded Action in the Actions Panel. 

Likes

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 ,
May 06, 2020 May 06, 2020

Copy link to clipboard

Copied

Hi, 

 

Thanks.

 

The key is option + '[' to layer down.

 

Now Ive sorted that, how can I get the action to automate over every layer as opposed to pressing play for every layer?

Cheers,

G

Likes

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
Adobe Community Professional ,
May 06, 2020 May 06, 2020

Copy link to clipboard

Copied

Likes

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 ,
May 07, 2020 May 07, 2020

Copy link to clipboard

Copied

Hi,

I'm cutting and pasting into script editor, but gettign a Syntax Error, ex[ect4ed end of line, etc. but found identifier. 

Help.

Thanks

Likes

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
Adobe Community Professional ,
May 07, 2020 May 07, 2020

Copy link to clipboard

Copied

What script editor? This is JavaScript, not AppleScript. Ensure that the file is saved as plain text file, change the file extension from .txt to .jsx

Likes

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 ,
May 07, 2020 May 07, 2020

Copy link to clipboard

Copied

Thanks for that. 

Ok, i copied it into text edit, saved, added extension .jsx. 

File>Scripts>browse and selected file.

 

Error 8 Syntax Error

Line: 1

->  {\rtf1\ansi\ansicpg1252\cocoartf2512

 

I'm copying the whole thing. 

Apologies, very inexperinced with this part.

Cheers,

Likes

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
Adobe Community Professional ,
May 07, 2020 May 07, 2020

Copy link to clipboard

Copied

{\rtf1\ansi\ansicpg1252\cocoartf2512

 

That bit in red is a clue, you saved the file from Rich Text Format mode, not from Plain Text mode (TextEdit has both modes).

 

You probably should read the link that I posted earlier:

 

Downloading and Installing Adobe Scripts

 

Likes

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 ,
May 07, 2020 May 07, 2020

Copy link to clipboard

Copied

I did, I try to save as .jsx but it adds the .rtf after. I rename the extension to just .jsx after I have saved the file, but it still come across with that error code. I'm using mac TextEdit.
Thx

Likes

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
Adobe Community Professional ,
May 07, 2020 May 07, 2020

Copy link to clipboard

Copied

Changing file extension does not change the format from RTF to plain text, you need to change the Format menu option as below:

 

rtf-wtf.png

 

Changing .txt to .jsx is OK, as it is still plain text.

Likes

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 ,
May 07, 2020 May 07, 2020

Copy link to clipboard

Copied

Great that did it. Thx.

 

Ok, the first link gave me this error code attached. 

 

The 3rd link seem to work, but I have no idea what it is called to attempt to see if it worked. I aim to follow these instructions attached. 

Years ago, I thought it was a lot easier to automate a process. 

Need to shut my eyes and try again in the morning, thx for your help. 

GScreen Shot 2020-05-07 at 9.39.41 pm.pngScreen Shot 2020-05-07 at 9.40.00 pm.png

Likes

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
Adobe Community Professional ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

»1, I created a new set, then a new action.

2, layer, layer mask, hide all.

3, load selection.

4, fill white.

5, deselect.

6, select next layer.

7, stop.«

Why do you add a Layer Mask, then load the Selection and fill instead of loading the Selection first and applying the Layer Mask then? 

Likes

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,
Thanks for that. 


When I have fresher eyes tomorrow morning, I'll take a better look. 

Regarding your last, no particular reason, like I said, I use it enough to know how much of the app I don't know.

Thanks again. 

Likes

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
Adobe Community Professional ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

// 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 (hasLayerMask (theLayers[i]) == true) {
var desc8 = new ActionDescriptor();
var ref5 = new ActionReference();
var idchannel = stringIDToTypeID( "channel" );
ref5.putEnumerated( idchannel, idchannel, stringIDToTypeID( "mask" ) );
desc8.putReference( stringIDToTypeID( "null" ), ref5 );
executeAction( stringIDToTypeID( "delete" ), desc8, DialogModes.NO );
};
// load selection;
   reselect ();
// apply layer mask;
if (selection == true) {makeLayerMask('RvlS')}
else {makeLayerMask('RvlA')};
}
};
////// 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; 
};
////// by mike hale, via paul riggott //////
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); 
}
};
////// add layer mask //////
function makeLayerMask(maskType) {
try {
if( maskType == undefined) maskType = 'RvlA' ; //from selection
// =======================================================
var idMk = charIDToTypeID( "Mk  " );
var desc3 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw  " );
var idChnl = charIDToTypeID( "Chnl" );
desc3.putClass( idNw, idChnl );
var idAt = charIDToTypeID( "At  " );
var ref1 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idMsk = charIDToTypeID( "Msk " );
ref1.putEnumerated( idChnl, idChnl, idMsk );
desc3.putReference( idAt, ref1 );
var idUsng = charIDToTypeID( "Usng" );
var idUsrM = charIDToTypeID( "UsrM" );
var idRvlA = charIDToTypeID(maskType);
desc3.putEnumerated( idUsng, idUsrM, idRvlA );
executeAction( idMk, desc3, DialogModes.NO );
} catch (e) {return false};
};
////// check for selection //////
function hasSelection(){
var ref10 = new ActionReference();
ref10.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
ref10.putEnumerated( charIDToTypeID( "Dcmn" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
var docDesc = executeActionGet(ref10);
return docDesc.hasKey(stringIDToTypeID("selection"));
};
////// reselect //////
function reselect () {
try {
var idsetd = charIDToTypeID( "setd" );
var desc7 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref2.putProperty( idChnl, idfsel );
desc7.putReference( idnull, ref2 );
var idT = charIDToTypeID( "T   " );
var idOrdn = charIDToTypeID( "Ordn" );
var idPrvs = charIDToTypeID( "Prvs" );
desc7.putEnumerated( idT, idOrdn, idPrvs );
executeAction( idsetd, desc7, DialogModes.NO );
} catch (e) {return false}
};
////// has layer mask //////
function hasLayerMask (theIndex) {  
var m_Dsc01, m_Ref01;  
m_Ref01 = new ActionReference();  
m_Ref01.putIndex(charIDToTypeID("Lyr "), theIndex);  
//m_Ref01.putEnumerated(sTID("layer"), cTID("Ordn"), cTID("Trgt"));  
m_Dsc01 = executeActionGet(m_Ref01);  
return m_Dsc01.hasKey(charIDToTypeID("Usrs"));  
};

Likes

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
Adobe Community Professional ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

@C_Pfaffenbichler, scripting never ceases to amaze me. If I understand by the comments, you used different snippets and put them together. Did you get them from ps-scripts? A French scripter was thinking about making a cross-apps repository.

Likes

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
Adobe Community Professional ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Those snippets are in part still from xbytor, Paul Riggot and Michael L Hale and in part just ScriptingListener.plugin-recordings (wrapped in functions) … 

I haven’t bought Davide Barranca’s Photoshop Scripting book but I suspect it may provide a fairly complete or at least a very relevant collection of Photoshop Scripting code. 

Likes

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 ,
May 06, 2020 May 06, 2020

Copy link to clipboard

Copied

Hi,

Looks impressive, but I dont know what that means or how to use it.
Thanks,

G

 

Likes

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
Adobe Community Professional ,
May 06, 2020 May 06, 2020

Copy link to clipboard

Copied

All should be answered here:

 

Downloading and Installing Adobe Scripts

 

Likes

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 ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

How to add black layers mask instead of white?

Likes

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
Adobe Community Professional ,
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)

btw did you see the solutions to: Removal of Groups with black masks 

Likes

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 ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

Hehe, yes I did! I am using that script too, and it works great.

My logic is probably not the best, but if my action is going to work in every instance I had to do it this way.

Likes

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
Adobe Community Professional ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

Okay, then please mark codes that do the job as correct solutions so other users of forum may know they are tested. I linked you also to other thread in that post from few days where left a script. If that is useful for you and does what you expected make it "green" for community 😉

Likes

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