Hi,
I am currently trying to paste an image into a layers mask but can't find any code in the Javascript reference for doing this.
Can I set up the mask as the activeChannel or can I select the mask directly through the activeLayer?
Hope someone can help!
Cheers,
James
Pasting into a Layer mask.
-
Paul MR
Pasting into a Layer mask.
Here is one example....
Code: Select allmain();
function main(){
if(!documents.length) return;
//select your layer first
if(!hasUserMask()){
alert("This layer does not have an user mask!");
return;
}
//get whatever you want to paste into the mask
var file = File.openDialog("Please select JPG file.","JPG File:*.jpg");
if(file == null ) return;
open(file);
activeDocument.selection.selectAll();
activeDocument.selection.copy();
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
//open mask ready for pasting
selectMask(true);
//paste selection
activeDocument.paste();
//close mask
selectMask(false);
//deselect
activeDocument.selection.deselect();
}
function selectMask(open){
var desc15 = new ActionDescriptor();
var ref9 = new ActionReference();
ref9.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Msk ') );
ref9.putName( charIDToTypeID('Lyr '), activeDocument.activeLayer.name);
desc15.putReference( charIDToTypeID('null'), ref9 );
desc15.putBoolean( charIDToTypeID('MkVs'), open );
executeAction( charIDToTypeID('slct'), desc15, DialogModes.NO );
};
function hasUserMask(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
return executeActionGet( ref ).getBoolean( stringIDToTypeID( 'hasUserMask' ) );
};
Code: Select allmain();
function main(){
if(!documents.length) return;
//select your layer first
if(!hasUserMask()){
alert("This layer does not have an user mask!");
return;
}
//get whatever you want to paste into the mask
var file = File.openDialog("Please select JPG file.","JPG File:*.jpg");
if(file == null ) return;
open(file);
activeDocument.selection.selectAll();
activeDocument.selection.copy();
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
//open mask ready for pasting
selectMask(true);
//paste selection
activeDocument.paste();
//close mask
selectMask(false);
//deselect
activeDocument.selection.deselect();
}
function selectMask(open){
var desc15 = new ActionDescriptor();
var ref9 = new ActionReference();
ref9.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Msk ') );
ref9.putName( charIDToTypeID('Lyr '), activeDocument.activeLayer.name);
desc15.putReference( charIDToTypeID('null'), ref9 );
desc15.putBoolean( charIDToTypeID('MkVs'), open );
executeAction( charIDToTypeID('slct'), desc15, DialogModes.NO );
};
function hasUserMask(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
return executeActionGet( ref ).getBoolean( stringIDToTypeID( 'hasUserMask' ) );
};
-
jameswatt3d
Pasting into a Layer mask.
Thanks for the help. That worked a dream!
Is there any way to understand the code in the selectMask function? How did you write it?
Is there any way to understand the code in the selectMask function? How did you write it?
-
Paul MR
Pasting into a Layer mask.
That function was created with code generated with the ScriptListener Plugin.
Just use alt/click on the user mask and look in the log for the generated code.
Hope this helps.
Just use alt/click on the user mask and look in the log for the generated code.
Hope this helps.
-
jameswatt3d
Pasting into a Layer mask.
Thanks Paul, will have a look at the ScriptListener. Sounds like it might be increasingly useful.
Cheers!
Cheers!