How to create masks action/script?
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);