Copy link to clipboard
Copied
Hi,
I've inspected the scripting listener code generated by dragging the topmost layer's mask to the layer below, substituting it.
Basically I start with this configuration:
and the result is this:
the recorded ActionManager is:
var idMk = charIDToTypeID( "Mk " );
var desc215 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var idChnl = charIDToTypeID( "Chnl" );
desc215.putClass( idNw, idChnl );
var idAt = charIDToTypeID( "At " );
var ref112 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idMsk = charIDToTypeID( "Msk " );
ref112.putEnumerated( idChnl, idChnl, idMsk );
var idLyr = charIDToTypeID( "Lyr " );
ref112.putName( idLyr, "Target" );
desc215.putReference( idAt, ref112 );
var idUsng = charIDToTypeID( "Usng" );
var ref113 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idMsk = charIDToTypeID( "Msk " );
ref113.putEnumerated( idChnl, idChnl, idMsk );
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref113.putEnumerated( idLyr, idOrdn, idTrgt );
desc215.putReference( idUsng, ref113 );
executeAction( idMk, desc215, DialogModes.NO );
which I've refactored for clarity's sake as:
function c2t (c) { return app.charIDToTypeID(c) }
var d1 = new ActionDescriptor();
var r1 = new ActionReference();
var r2 = new ActionReference();
d1.putClass( s2t('new'), s2t('channel') );
r1.putEnumerated( s2t('channel', s2t('channel'), s2t('mask') );
r1.putName( s2t('layer'), 'Target');
d1.putReference( s2t('at'), r1 );
r2.putEnumerated( s2t('channel'), s2t('channel'), s2t('mask') );
r2.putEnumerated( s2t('layer'), s2t('ordinal'), s2t('targetEnum') );
d1.putReference( s2t('using'), r2 );
executeAction( s2t('make'), d1, DialogModes.NO );
Now, for some reason if I go back to the very exact starting point (first screenshot) and I run the above code - no matter whether the refactored or original version - I got the usual "General Photoshop error, etc" that happens when your AM code is wrong and/or tries to perform some action that is forbidden.
I wonder whether this is a scriptinglistener recording bug or something else.
I've seen that the code runs "almost" correctly if the bottom layer has no mask - in this case the mask is not moved but duplicated (i.e. same mask for both the layer above and below).
So possibly the SL code is missing the "replace" existing mask and "move" mask part - is hard to guess what they should be...
Thank you in advance for any help,
Davide Barranca
---
Copy link to clipboard
Copied
When I tried this is prompted if the mask should be deleted and this does not record in scriptlistener, so one way could be to delete the mask:-
copyMask(3,2);
function copyMask(FROMid,TOid,Duplicate) {
if(Duplicate == undefined) Duplicate = false;
deleteMask(TOid);
var desc = new ActionDescriptor();
desc.putClass( charIDToTypeID('Nw '), charIDToTypeID('Chnl') );
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Msk ') );
ref.putIdentifier(charIDToTypeID('Lyr '), TOid);
desc.putReference( charIDToTypeID('At '), ref );
var ref2 = new ActionReference();
ref2.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Msk ') );
ref2.putIdentifier(charIDToTypeID('Lyr '), FROMid);
desc.putReference( charIDToTypeID('Usng'), ref2 );
desc.putBoolean( charIDToTypeID('Dplc'), Duplicate ); //true duplicate
executeAction( charIDToTypeID('Mk '), desc, DialogModes.NO );
};
function deleteMask(ID) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Msk ') );
ref.putIdentifier( charIDToTypeID('Lyr '), ID);
desc.putReference( charIDToTypeID('null'), ref );
try{
executeAction( charIDToTypeID('Dlt '), desc, DialogModes.NO );
}catch(e){}
};
Copy link to clipboard
Copied
I tested this in CS6/Win7 and am seeing the same problem.
I wonder whether this is a scriptinglistener recording bug or something else.
This would be my guess. File a bug report. There are people in Adobe whose are responsible for fixing SL Code problems like this or to make sure that SL Code is being created for places it does not currently exist. That's about as much as I can say beyond file bug reports when you see problems like this.
Copy link to clipboard
Copied
It might be better to use another method, say use apply image to copy the source layer mask to the target layer mask, then delete the original layer mask. Just dragging things often causes problems with scriptlistener. I found that out trying to record moving layers. Tom Ruark said that I needed to use the menu commands to capture the code correctly.
Copy link to clipboard
Copied
Also you could load top layer transparency as a selection. Save the selection as an alpha channel. Then delete the current layer layer mask. Select layer backwards. Delete the current layer layer mask. Then load the Alpha channel as a selection if the selection is not still active and add a layer mask to the current layer. Its more steps but may work.