Can this be code be reduced? (Extendscript) (ScriptingListener plug-in)

13 views Asked by At

Please bear with me, I’m still at the very bottom of the beginner level and I’ve just discovered the “ScriptingListener plug-in” yesterday.

I picked this code from the plug in:

var idMk = charIDToTypeID( "Mk  " );
var desc234 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
    var ref1 = new ActionReference();
    var idAdjL = charIDToTypeID( "AdjL" );
    ref1.putClass( idAdjL );
desc234.putReference( idnull, ref1 );
var idUsng = charIDToTypeID( "Usng" );
    var desc235 = new ActionDescriptor();
    var idType = charIDToTypeID( "Type" );
        var desc236 = new ActionDescriptor();
        var idpresetKind = stringIDToTypeID( "presetKind" );
        var idpresetKindType = stringIDToTypeID( "presetKindType" );
        var idpresetKindDefault = stringIDToTypeID( "presetKindDefault" );
        desc236.putEnumerated( idpresetKind, idpresetKindType, idpresetKindDefault );
        var idExps = charIDToTypeID( "Exps" );
        desc236.putDouble( idExps, 0.000000 );
        var idOfst = charIDToTypeID( "Ofst" );
        desc236.putDouble( idOfst, 0.000000 );
        var idgammaCorrection = stringIDToTypeID( "gammaCorrection" );
        desc236.putDouble( idgammaCorrection, 1.000000 );
    var idExps = charIDToTypeID( "Exps" );
    desc235.putObject( idType, idExps, desc236 );
var idAdjL = charIDToTypeID( "AdjL" );
desc234.putObject( idUsng, idAdjL, desc235 );
executeAction( idMk, desc234, DialogModes.NO );

..and reduced it to this:

function exeAction (Type, Option, Value) {

    var desc00 = new ActionDescriptor();

    if (Type == 'Mode') {...}    
    if (Type == 'placeLayer') {...}
    if (Type == 'Exposure') {

        var desc01 = new ActionDescriptor();
        var desc02 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putClass (charIDToTypeID ('AdjL'));
        desc00.putReference (charIDToTypeID ('null'), ref1);
        desc02.putDouble (charIDToTypeID ('Exps'), Value[0]);
        desc02.putDouble (charIDToTypeID ('Ofst'), Value[1]);
        desc02.putDouble (stringIDToTypeID ('gammaCorrection'), Value[2]);
        desc01.putObject (charIDToTypeID ('Type'), charIDToTypeID('Exps'), desc02);
        desc00.putObject (charIDToTypeID ('Usng'), charIDToTypeID('AdjL'), desc01);
        executeAction (charIDToTypeID ('Mk  '), desc00, DialogModes.NO);}
}

..it’s a simple code that adds an adjustment “Exposure” layer. At first I was struggling to understand how the executeAction works at all (still not all clear). Now I know from Photoshop javascript ref 2020 that it “Plays an Action Manager event”, it uses (number, ActionDescriptor, DialogModes) as arguments and an action specified by the ActionDescriptor parameters. I can see that the parameters are “nested” inside the ActionDescriptor. What I don’t know is:

  1. Does the nesting order inside ActionDescriptor matter?
  2. What is the reference used for?
  3. How to decipher what the undocumented ID’s do? (Haha)

charIDToTypeID ('Usng') Is not listed under Apendix A in Photoshop javascript ref 2020, I’m guessing for “Using”, like put object into decs00 as adjustment layer using decs01 parameters. Is there perhaps a site where the undocumented ID’s are listed? Does anyone know of a ActionDescriptor tutorial?

Any info would be sincerely appreciated. Just reduced code without any comments, reference to a guide or even just a comment like "no this code cannot be reduced."

Thanks in advance.

0

There are 0 answers