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

Script to add layer mask to all layers but background?

New Here ,
Apr 02, 2014 Apr 02, 2014

Copy link to clipboard

Copied

I've been a professional editor/retoucher for photographers for the past three years. I use a lot of actions, but I've never branched into scripts until now. I'm trying to refine my workflow and scripts seem like the next logical step.

I do a lot of interiors work, which is basically manual HDR. Here's my current build process, which I'd love to find a way to script. I tried to be very clear, but let me know if this needs fleshing out. I'm using Photoshop CS5.

1. Pull up bracketed, color-corrected TIFFs in Bridge.

2. Re-order as needed, with main exposure at the bottom. Click "Tools" > "Photoshop" > "Load as Photoshop layers" to get a PSD with layers in correct order and main exposure as background (base) layer.

3. Manually go through each layer and add a Hide All layer mask to every layer except the background layer.

4. Save as a PSD, using the original name of the background layer as the filename. To do this I just copy the layer name (example.tiff), paste in the Save dialog and then use the dropdown menu to select PSD (thus saving as example.psd).

I'm hoping to automate steps 3 and 4 as they are the most time consuming for me. Any input is appreciated!!

Thanks again.

TOPICS
Actions and scripting

Views

8.4K

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 03, 2014 Apr 03, 2014

Yes your change is good.  That way the last layer won't have a mask applied.  I wasn't sure if you wanted that, but put in the check for the background layer. 

As far as saving, what file format do you want to save to?  Here's how I save a psd:

var docRef = activeDocument

var doneFolder = new Folder('/c/photos/')

var layerName = docRef.activeLayer.name

var psdOptions = new PhotoshopSaveOptions();

psdOptions.layers = true;

app.displayDialogs = DialogModes.ALL;//include this line if you want the dialog

...

Votes

Translate

Translate
Adobe
New Here ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

That sets the active layer - I confirmed it with an alert.  It still doesn't run the fuction layerMask on the active layer set by the script.  It only runs the function on the layer selected in Photoshop on the layers palette.

 

I've noticed that none of the functions written like the one I pasted above work when the active layer is set by code earlier in the 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 ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Sorry, I'm just not getting it...

 

before-after.png

 

#target photoshop

activeDocument.activeLayer = activeDocument.layerSets["Group 1"].layers["FOO"];
layerMask();

function layerMask() {
    var idmake = stringIDToTypeID("make");
    var desc6898 = new ActionDescriptor();
    var idnew = stringIDToTypeID("new");
    var idchannel = stringIDToTypeID("channel");
    desc6898.putClass(idnew, idchannel);
    var idat = stringIDToTypeID("at");
    var ref412 = new ActionReference();
    var idmask = stringIDToTypeID("mask");
    ref412.putEnumerated(idchannel, idchannel, idmask);
    desc6898.putReference(idat, ref412);
    var idusing = stringIDToTypeID("using");
    var iduserMaskEnabled = stringIDToTypeID("userMaskEnabled");
    var idrevealAll = stringIDToTypeID("revealAll"); // ("hideAll")
    desc6898.putEnumerated(idusing, iduserMaskEnabled, idrevealAll); // idhideAll
    executeAction(idmake, desc6898, DialogModes.NO);
}

 

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
New Here ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Yeah looks like it's working for you.  I'm not sure why I get different behavior from it.  I'll try resetting Photoshop preferences and see if that clears it up.  Thanks for the help!

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
New Here ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

LATEST

I got rid of everything but the script you pasted here and it worked!  It looks like the problem in my original script is somehwere around this:

var lyrAct = activeDocument.activeLayer;

 

Maybe I have been using that incorrectly?

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