Skip to main content
Participant
October 26, 2008
Question

How to "add layer mask"

  • October 26, 2008
  • 3 replies
  • 11704 views
Hi, i readed all JavaScript Reference but now found function to add mask to layer, can anyone have solution to this?

PS I have some solution(i got it through scriptlistener.8bi):
"
var id21 = charIDToTypeID( "Mk " );
var desc4 = new ActionDescriptor();
var id22 = charIDToTypeID( "Nw " );
var id23 = charIDToTypeID( "Chnl" );
desc4.putClass( id22, id23 );
var id24 = charIDToTypeID( "At " );
var ref2 = new ActionReference();
var id25 = charIDToTypeID( "Chnl" );
var id26 = charIDToTypeID( "Chnl" );
var id27 = charIDToTypeID( "Msk " );
ref2.putEnumerated( id25, id26, id27 );
desc4.putReference( id24, ref2 );
var id28 = charIDToTypeID( "Usng" );
var id29 = charIDToTypeID( "UsrM" );
var id30 = charIDToTypeID( "RvlA" );
desc4.putEnumerated( id28, id29, id30 );
executeAction( id21, desc4, DialogModes.NO );
"
Mb there is another solution not such hard to understand and write?
This topic has been closed for replies.

3 replies

Royi A
Inspiring
April 13, 2009

I didn't get the code (Too Messy).

Could anyone elaborate how to create a mask using a script?

Thanks.

Paul Riggott
Inspiring
April 13, 2009

Yet another version....

makeLayerMask('HdSl');

function makeLayerMask(maskType) {
if( maskType == undefined) maskType = 'RvlS' ; //from selection
//requires a selection 'RvlS'  complete mask 'RvlA' otherThanSelection 'HdSl'
    var desc140 = new ActionDescriptor();
    desc140.putClass( charIDToTypeID('Nw  '), charIDToTypeID('Chnl') );
        var ref51 = new ActionReference();
        ref51.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Msk ') );
    desc140.putReference( charIDToTypeID('At  '), ref51 );
    desc140.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('UsrM'), charIDToTypeID(maskType) );
    executeAction( charIDToTypeID('Mk  '), desc140, DialogModes.NO );
}

Royi A
Inspiring
April 13, 2009

Could you tell me how do I use it?

Lets say "CurrLay" is my active layer which I want to add a mask to.

How do I do it?

I add your code at the beginning of my script then...

Thanks.

_dark_gf_Author
Participant
October 27, 2008
Thx.
Known Participant
October 26, 2008
>
> PS I have some solution(i got it through scriptlistener.8bi):]

This code is the only way to do it.


> Mb there is another solution not such hard to understand and write?

All that can be done is make that code a bit more readable.

cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

createLayerMask = function(doc, layer, fromSelection) {
var desc = new ActionDescriptor();
desc.putClass(cTID("Nw "), cTID("Chnl"));
var ref = new ActionReference();
ref.putEnumerated(cTID("Chnl"), cTID("Chnl"), cTID("Msk "));
desc.putReference(cTID("At "), ref);
if (fromSelection == true) {
desc.putEnumerated(cTID("Usng"), cTID("UsrM"), cTID("RvlS"));
} else {
desc.putEnumerated(cTID("Usng"), cTID("UsrM"), cTID("RvlA"));
}
executeAction(cTID("Mk "), desc, DialogModes.NO);
}
};



If you have a lot of code like this, you can also use create symbols like this:

PSClass.Channel = cTID('Chnl');
PSKey.New = cTID('Nw ');
PSEnum.RevealAll = cTID('RvlA');
PSEnum.RevealSelection = cTID('RvlS');

and use them instead.

-X