Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I didn't get the code (Too Messy).
Could anyone elaborate how to create a mask using a script?
Thanks.
Copy link to clipboard
Copied
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 );
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Once you have your current layer selected you have three options
You just need to call the function. ie:
makeLayerMask('HdSl'); //This needs a selection and that selection will be hidden
makeLayerMask('RvlS'); //This needs a selection and that selection will be shown
makeLayerMask('RvlA'); //This is a complete mask no selection required
Copy link to clipboard
Copied
Thank you.
I have 2 problems a problem:
The way I used it, I det my active layer then wrote this:
makeLayerMask ('RvlA');
Thanks.
Copy link to clipboard
Copied
Use makeLayerMask ("HdAl") with the above function
Copy link to clipboard
Copied
Michael L Hale wrote:
Use makeLayerMask ("HdAl") with the above function
Thanks, Works great!
Is there a way to make it work on LayerSets?
It seems to work only on layerArts.
Thank you again.
Copy link to clipboard
Copied
That function works with layersets as well. With either layers or layersets, the layer you want to apply the mask to needs to be the activeLayer.
Copy link to clipboard
Copied
Well, it doesn't work for me for some reason.
I'm setting a LayerSet as the active layer by:
app.activeDocument.activeLayer = app.activeDocument.layerSets.getByName("LayerSetName");.
I verified it by:
alert (app.activeDocument.activeLayer);
and got the LayerSetName as a result.
Yet just after making it the active layer I used:
makeLayerMask ('HdSl');
Yet, I got an Erros Message the last line of the function:
executeAction (charIDToTypeID('Mk '), desc140, DialogModes.NO);
It says: "General Photoshop error occoured. This functionality may not be available in this version of Photoshop".
I have CS4.
How can I fix it?
Thanks.
Managed to make it work.
I just forgot the selection, thanks.
Copy link to clipboard
Copied
@Paul_Riggott,
How can get back the "Focus" to the layer itself after creating the mask?
Thank You.
Copy link to clipboard
Copied
This selects the layer.
function selectRGB() {
var desc25 = new ActionDescriptor();
var ref11 = new ActionReference();
ref11.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('RGB ') );
desc25.putReference( charIDToTypeID('null'), ref11 );
desc25.putBoolean( charIDToTypeID('MkVs'), false );
executeAction( charIDToTypeID('slct'), desc25, DialogModes.NO );
};
Copy link to clipboard
Copied
@SuperMerlin,
It worked!
Anyway to switch between the Mask and the RGB for viewing (Like Ctrl Click)?
Thank You.
Copy link to clipboard
Copied
Ctrl \
Ctrl 2
Copy link to clipboard
Copied
Hi,
I meant using a Script.
I managed to create this:
function SwitchToMask(){
var idSlct = charIDToTypeID( "slct" );
var idNull = charIDToTypeID( "null" );
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idMsk = charIDToTypeID( "Msk " );
var idMkVs = charIDToTypeID( "MkVs" );
var switchToMaskDescriptor = new ActionDescriptor();
var actionRef = new ActionReference();
actionRef.putEnumerated( idChnl, idChnl, idMsk );
switchToMaskDescriptor.putReference( idNull, actionRef );
switchToMaskDescriptor.putBoolean( idMkVs, true );
executeAction( idSlct, switchToMaskDescriptor, DialogModes.NO );
}
function SwitchToRgb(){
var idSlct = charIDToTypeID( "slct" );
var idNull = charIDToTypeID( "null" );
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idRGB = charIDToTypeID( "RGB " );
var idMkVs = charIDToTypeID( "MkVs" );
var switchToRgbDescriptor = new ActionDescriptor();
var actionRef = new ActionReference();
actionRef.putEnumerated( idChnl, idChnl, idRGB );
switchToRgbDescriptor.putReference( idNull, actionRef );
switchToRgbDescriptor.putBoolean( idMkVs, false );
executeAction( idSlct, switchToRgbDescriptor, DialogModes.NO );
}
Maybe it will assist someone.
Copy link to clipboard
Copied
If you want to toggle between you could use this function.
function toggleRGBMask(){
var ref = new ActionReference();
ref.putProperty(charIDToTypeID('Prpr'),stringIDToTypeID('channelName'));
ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
var desc = executeActionGet(ref);
var mask = desc.getString(stringIDToTypeID('channelName'));
if(mask=='RGB') rgbmask = 'Msk ' else rgbmask = 'RGB ';
var desc25 = new ActionDescriptor();
var ref11 = new ActionReference();
ref11.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID(rgbmask) );
desc25.putReference( charIDToTypeID('null'), ref11 );
desc25.putBoolean( charIDToTypeID('MkVs'), false );
executeAction( charIDToTypeID('slct'), desc25, DialogModes.NO );
};
Copy link to clipboard
Copied
Hi! Could someone can help me with this code:
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 );
}
Well in that way i can only make mask after select one layer, but i want to make masks for each layer in my psd file.
Thanks for answers in advance!
Copy link to clipboard
Copied
Hi Paul and others,
I'm trying to add your code snippet to my Applescript because there is no other way in Photoshop to work with layer masks.
Your Javascript works perfectly except when the current layer has already a mask.
In this case, a general error 8800 occurs and no matter if I insert the Javascript in a try statement.
Is there a way to test if a mask exists for the current layer and then delete it?
Thank you for your help.
Copy link to clipboard
Copied
Here you are...
function hasLayerMask() {
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc = executeActionGet(ref);
return desc.hasKey(charIDToTypeID("UsrM"));
}
function deleteMask() {
var desc523 = new ActionDescriptor();
var ref325 = new ActionReference();
ref325.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc523.putReference( charIDToTypeID('null'), ref325 );
executeAction( charIDToTypeID('Dlt '), desc523, DialogModes.NO );
};
Copy link to clipboard
Copied
Paul,
Your code helps me a lot.
At last, I'm able to create layer masks the way I wanted to.
Thank you again.