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
// 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
...
Copy link to clipboard
Copied
I thought I did?
Copy link to clipboard
Copied
So try please again if that didn't work in Jul 03, 2021 & in the other thread.
Copy link to clipboard
Copied
"The command "Make" is not currently available".
Copy link to clipboard
Copied
Running which code you're getting this alert?
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?
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')};
Copy link to clipboard
Copied
Works!
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.
Copy link to clipboard
Copied
Please explain and post screenshots to illustrate the problem.
Copy link to clipboard
Copied
I am sorry, my bad. I can't manage to recreate it.
Copy link to clipboard
Copied
So there is no problem about it for you anymore?
Copy link to clipboard
Copied
No, not a problem. Thought it was this script but I was wrong.
Copy link to clipboard
Copied
You could also place the layers inside a clipping group, it is not exactly a layer group...
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
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?
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
Link to action:
/*
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()');
Copy link to clipboard
Copied
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;
};
Copy link to clipboard
Copied
This works perfect for what I need, and applies my action on selected layers.
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
}
Copy link to clipboard
Copied
Thank you, Stephen!