Copy link to clipboard
Copied
Hi,
I want to use the "Apply Image" function in my JavaScript.
Since this function is not available in the API, I recorded the function calls with the "ScriptListener.8li"
Here is the code, that has been generated (I reformated the code a bit to make it more readable):
function testIt() {
var ref24 = new ActionReference();var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idRGB = charIDToTypeID( "RGB " );
ref24.putEnumerated( idChnl, idChnl, idRGB );var idLyr = charIDToTypeID( "Lyr " );
ref24.putName( idLyr, "My Layer Name" );
var desc30 = new ActionDescriptor();
var idT = charIDToTypeID( "T " );
desc30.putReference( idT, ref24 );var idClcl = charIDToTypeID( "Clcl" );
var idClcn = charIDToTypeID( "Clcn" );
var idSbtr = charIDToTypeID( "Sbtr" );
desc30.putEnumerated( idClcl, idClcn, idSbtr );var idScl = charIDToTypeID( "Scl " );
desc30.putDouble( idScl, 2.000000 );var idOfst = charIDToTypeID( "Ofst" );
desc30.putInteger( idOfst, 128 );var desc29 = new ActionDescriptor();
var idWith = charIDToTypeID( "With" );
var idClcl = charIDToTypeID( "Clcl" );
desc29.putObject( idWith, idClcl, desc30 );var idAppI = charIDToTypeID( "AppI" );
executeAction( idAppI, desc29, DialogModes.NO );
}
The Problem: The function is based on the layer name.
This can lead to problems if two layers have the same name:
ref24.putName( idLyr, "My Layer Name" );
How can I get this function work with "layer.id" or "layer.itemIndex"?
I tryed for more than 6 hours and haven't found a solution.
Please help!
Something on the lines of.
...function apply(ID) {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('RGB ') );
ref.putIdentifier(charIDToTypeID('Lyr '), ID); //Layer ID
//ref.putIndex( charIDToTypeID('Lyr '), idx ); //Layer Index
var desc = new ActionDescriptor();
desc.putReference( charIDToTypeID('T '), ref );
desc.putEnumerated( charIDToTypeID('Clcl'), charIDToTypeID('Clcn'), charIDToTypeID('Sbtr') );
desc.putDouble( ch
Copy link to clipboard
Copied
Something on the lines of.
function apply(ID) {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('RGB ') );
ref.putIdentifier(charIDToTypeID('Lyr '), ID); //Layer ID
//ref.putIndex( charIDToTypeID('Lyr '), idx ); //Layer Index
var desc = new ActionDescriptor();
desc.putReference( charIDToTypeID('T '), ref );
desc.putEnumerated( charIDToTypeID('Clcl'), charIDToTypeID('Clcn'), charIDToTypeID('Sbtr') );
desc.putDouble( charIDToTypeID('Scl '), 2.000000 );
desc.putInteger( charIDToTypeID('Ofst'), 128 );
var desc2 = new ActionDescriptor();
desc2.putObject( charIDToTypeID('With'), charIDToTypeID('Clcl'), desc );
try{
executeAction( charIDToTypeID('AppI'), desc2, DialogModes.NO );
}catch(e){}
};
Copy link to clipboard
Copied
Thanks so much, you are awsome!