• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Apply Image with layer.id or layer.itemIndex

Guest
Aug 15, 2015 Aug 15, 2015

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!

TOPICS
Actions and scripting

Views

767

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Aug 15, 2015 Aug 15, 2015

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

...

Votes

Translate

Translate
Adobe
Enthusiast ,
Aug 15, 2015 Aug 15, 2015

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){}

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 15, 2015 Aug 15, 2015

Copy link to clipboard

Copied

LATEST

Thanks so much, you are awsome!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines