Need to understand action descriptors and action references

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Nightshade

Need to understand action descriptors and action references

Post by Nightshade »

The stuff that's in Adobe's manual isn't very thourough - I've read it and I don't really grasp the concept of these action descriptors and action references fully.

I already know MEL and Python, and I have a quite decent understanding of the javascript syntax so I think that "hey, it can't be too complex can it?"

I think that maybe the best approach to this is to take a simple script and go through it row by row, dissecting the things that it does. I've already identified most of the stuff here but like I said, I do not fully understand the concepts of that action descriptor and action reference. The script below moves the active layer one step backwards:
Code: Select allif (app.documents.length > 0) {
   var actDesc = new ActionDescriptor();
   var actRef = new ActionReference();   
   var method = charIDToTypeID("slct");
   actRef.putEnumerated(charIDToTypeID("Lyr "),charIDToTypeID("Ordn"),charIDToTypeID("Bckw"));
   actDesc.putReference(charIDToTypeID("null"),actRef);
   actDesc.putBoolean(charIDToTypeID("MkVs"),false);
   
   executeAction(method,actDesc,DialogModes.NO); // Executes "Select", with the action descriptor and with no dialogs. The action descriptor is a pointer?
}
Row 1: If we have a document open
Row 2 and 3: Create new object, ActionDescriptor, store in a variable. Do the same for the object ActionReference
Row 4: Get the event ID for select and store this in a variable called method.
Row 5: This is where I don't fully understand what's going on, but my guess is: putEnumerated adds a tuple-object to the action reference that contains the event IDs for "layer" (Lyr), "ordinance" (Ordn) and Backwards (Bckw)?
Row 6: Sets a null value for the action reference, which is then added to the action descriptor. If the action descriptor is nothing but a label for the action reference, why do we need to use descriptors at all?
Row 7: The event ID "Make visible" with a value of false is added to the action descriptor. I've found that the script runs just fine even without this line, and setting the bool to true does not turn on the visibility of any hidden layer under the current active layer. So this row seems useless to me.
Row 9: The execution. run "select", run the action descriptor with no dialogs. Hmm.. ok... so the action descriptor is just a pointer to the action reference, that is a container for the real command?