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

How to create masks action/script?

Community Beginner ,
Feb 06, 2020 Feb 06, 2020

Copy link to clipboard

Copied

Hi,

 

I'm a noob of actions and scripting for PS.

I'd like to automate two processes that I've called "Apply Masks" and "Regenerate Masks" in Ps CS6 and above.

The most important is "Apply Mask", it would be a timesaver for what I've to do.

 

Apply Masks

For each layer,  if it has a mask, duplicate the layer (with the mask) near to the original (presumeably above?). To one version (aka the "duplicate") apply the mask. Then lock and hide the other version (aka the "source").

 

Regenerate Masks

If we have a "duplicate", delete it and unlock and show the respective "source".

 

How can I make that? What I've to study? Automations? Scripting? Both? I know nothing.

 

Thank you

UPDATE:
I realized that actions weren't enough so I wrote a JS Script to iterate through all layers, but I gave up at the step of checking if the layer has a layer mask.

 

// Iterate through top level artLayers
function outputTopLevelArtLayers(layerNode) {    
    for (var i=0; i<layerNode.length; i++) {
		alert("ArtLayer: "+layerNode[i].name);		
		
		// Check if it has a layer mask, then apply it
		// ...
    }
}

// Iterate through layerSets
function outputLayerSets(layerNode) {    
    for (var i=0; i<layerNode.length; i++) {
		alert("LayerSet: "+layerNode[i].name);
        outputLayerSets(layerNode[i].layerSets);
        for(var layerIndex=0; layerIndex < layerNode[i].artLayers.length; layerIndex++) {
            var layer=layerNode[i].artLayers[layerIndex];
            alert("ArtLayer: " + layer.name);
			
			// Check if it has a layer mask, then apply it
			// ...
        }
    }
}

outputTopLevelArtLayers(app.activeDocument.artLayers);
outputLayerSets(app.activeDocument.layerSets);

Views

1.4K
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 Expert ,
Feb 06, 2020 Feb 06, 2020

Copy link to clipboard

Copied

Hi check this video you will understand all....Regards

 

https://youtu.be/GiiSySY5nN0

Ali Sajjad / Graphic Design Trainer / Freelancer / Adobe Certified Professional

Votes

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

Copy link to clipboard

Copied

Yes, using shortcuts (usually ALT+[ and ] )  to target the layers is the key, so that it ignores the layer names, and just targets the layer above or below. 

Votes

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

Copy link to clipboard

Copied

As has been mentioned, with actions you can indeed automate much of this for the Apply Masks requirement...

 

You could use a conditional action step to test if the current layer has a pixel mask and if it did the conditional action step would run another action that would duplicate the active layer, apply the mask, select the relative backwards layer hide and lock.

 

Then you could manually select the next layer and run the action again.

 

All of this is possible with actions.

 

That being said, to automatically do this to all layers if the layer count may vary, you would need a helper script to loop the action over all of the layers (or script the entire process where layer names would be better handled).

 

You would not need a script if all of the layers had a consistent count that the action would then work its way through in a linear fashion. You might be able to build the action with more steps than you think you require, then it would simply error and you would cancel the playback if there were no layers left to process... This may or may not work as expected, I have not tested.

 

I have not thought about the Regenerate Masks requirement.

Votes

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 Beginner ,
Feb 08, 2020 Feb 08, 2020

Copy link to clipboard

Copied

Thank you for the answer.

Yes, the number of layers can vary a lot.

Votes

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 ,
Feb 08, 2020 Feb 08, 2020

Copy link to clipboard

Copied

Stephen, don't you think this style of mini-scripts (iterate through layers) should be integrated in Ps, much like the conditional actions?

Votes

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 Beginner ,
Feb 08, 2020 Feb 08, 2020

Copy link to clipboard

Copied

Check the original post. Thank You.

Votes

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 ,
Feb 09, 2020 Feb 09, 2020

Copy link to clipboard

Copied

Filippo, what I was saying is that sort of code snippet should be built-in Ps, for "mere mortals" (non-scripters) like me...

Votes

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 ,
Feb 08, 2020 Feb 08, 2020

Copy link to clipboard

Copied

Conditional actions need to have more conditions, or the ability to add a variable wildcard value to extend them, similar to what I request here using XMP metadata as the wildcard entry:

 

https://feedback.photoshop.com/photoshop_family/topics/bridge-batch-rename-using-any-xmp-data

 

However, to answer your loaded question – Yes!

 

There are many basic automation extensions that could be added to Photoshop. It is a tricky subject, some automation routines are obvious and generic. Others are very specific. I am thankful that we have the ability to script and extend Photoshop further than actions allow, however at the same time I wish that actions could do more and that scripting was not needed in so many cases.

 

 

 

Votes

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 ,
Feb 10, 2020 Feb 10, 2020

Copy link to clipboard

Copied

LATEST

I had a wild guess, trying to create ping-pong actions, that linked to each other. I'm able to create them, if I disable the play step in the second one, but it will refuse to launch an already running action.

(I need to re-read Danny Rafael's mother of all actions tutorials where it must already be explained...)

Votes

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 ,
Feb 08, 2020 Feb 08, 2020

Copy link to clipboard

Copied

I tried your script code but it does not work for me.

 

I have tested the following with success in a limited testing model (however, I don't know your layer structure so it may not work the same):

 

Screen Shot 2020-02-09 at 11.21.58.pngexpand image

 

You can download the action in the link below:

https://www.dropbox.com/s/yyum9jvntvlhjmb/Apply%20Mask.atn?dl=0

 

Then using a helper script to run the conditional action on all layers (if the condition is true, then the conditional action plays the action to apply layer masks):

 

 

//forums.adobe.com/message/8895266#8895266
//forums.adobe.com/message/8895401#8895401

var ActionName = "Apply Mask Conditional"; // Replace with your action name
var ActionSet = "Apply Mask"; // Replace with your action set name

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]);
    } 
}

 

 

Layers Before:

 

Screen Shot 2020-02-09 at 13.37.25.pngexpand image

 

Layers After:

 

Screen Shot 2020-02-09 at 13.37.35.pngexpand image

Votes

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 Beginner ,
Feb 09, 2020 Feb 09, 2020

Copy link to clipboard

Copied

Thanks You very much Stephen, great hints

Votes

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 ,
Feb 10, 2020 Feb 10, 2020

Copy link to clipboard

Copied

So how did the action set download and matching script code that I provided work out?

Votes

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