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
Post your action? How does your action know which layers to add the layer mask to?
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?
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,
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.
»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.
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
Copy link to clipboard
Copied
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
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
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,
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
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
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:
Changing .txt to .jsx is OK, as it is still plain text.
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.
G
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?
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.
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"));
};
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.
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.
Copy link to clipboard
Copied
Hi,
Looks impressive, but I dont know what that means or how to use it.
Thanks,
G
Copy link to clipboard
Copied
Copy link to clipboard
Copied
How to add black layers mask instead of white?
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
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.
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 😉