How to Load channel as selection, add it as a layer mask and save layer as PNG with the mask applied
So my PSD files have multiple layers, and some of them have a channel with a alpha mask, that needs to be applied to them before saving.
My script is at the point, that it's rasterizing all the layers in the beginning and later, in a loop, it's going through all the layers that should be saved. Before saving I'm checking if the current layer has a channel (I can figure that out by their names), that needs to be applied as a layer mask to the current layer:
My problem at the moment: How can I add the channel as a layer mask?
I already tried to record the action with ScriptingListener and got this Code:
Before I call this function, I thought it would be enough to just load the layer to the selection like so:
function MaskToLayer() {
var idMk = charIDToTypeID( "Mk " );
var desc11 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var idChnl = charIDToTypeID( "Chnl" );
desc11.putClass( idNw, idChnl );
var idAt = charIDToTypeID( "At " );
var ref3 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idMsk = charIDToTypeID( "Msk " );
ref3.putEnumerated( idChnl, idChnl, idMsk );
desc11.putReference( idAt, ref3 );
var idUsng = charIDToTypeID( "Usng" );
var idUsrM = charIDToTypeID( "UsrM" );
var idRvlA = charIDToTypeID( "RvlA" );
desc11.putEnumerated( idUsng, idUsrM, idRvlA );
executeAction( idMk, desc11, DialogModes.NO );
}
