Can Someone Clarify This To A Beginner

Scenario:
Getting itemIndex of the Active Layer

Using Alchemist, I get this code…

const result = await batchPlay(
[
   {
      "_obj": "get",
      "_target": [
         {
            "_property": "itemIndex"
         },
         {
            "_ref": "layer",
            "_id": 32
         },
         {
            "_ref": "document",
            "_id": 327
         }
      ],
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   }
],{
   "synchronousExecution": false,
   "modalBehavior": "fail"
});

I assume that this portion indicates the current active layer ID number and doesnt work with another layer item as I guess that another layer item will have a different ID number.

{
“_ref”: “layer”,
“_id”: 32
},

By changing it to the folllowing does appear to to work.

{
“_ref”: “layer”,
“_enum”: “ordinal”,
“_value”: “targetEnum”
},

Not sure what enum means, but at a guess does this somehow indicate that we are targeting the selected layer regardless of its ID number ?

Ian

targetEnum usually means selected item (document, layer, path, channel,…)

Thanks for the clarrification. I knew it worked but I just wanted to clarify I was on the right thinking rather than working blind.

Now I have the ItemIndex, I am trying to select that layer by its Index number but I just cant seemt o get my head around this.

I tried adding _property and a value thinking this would do it but i must be missing something.

My theory behind this was… Select layer with itemIndex of value 2

{
“_obj”: “select”,
“_target”: [
{
“_ref”: “layer”,
“_property”: “itemIndex”,
“_value”: 2
}
],
“makeVisible”: false,
“_isCommand”: true,
“_options”: {
“dialogOptions”: “dontDisplay”
}
}

You’re close to the solution, but itemIndex is a property of the Layer Descriptor and you can’t target specific properties inside a reference. That would be as if you’d say “Select the layer that has opacity 50%”.

You can target a property, but it will be nested inside it’s own object inside the _target array, for example:

{
  _obj: 'get',
  _target: [{ _property: 'itemIndex' }, { _ref: 'layer', _enum: 'ordinal', _value: 'targetEnum' }],
}

(This would get the itemIndex of the selected layer).

However, what you want is to specify the layer reference. For references, there are a handful of keywords that you can use, such as _name, _index or _id. (example)

Is there a way using the debug tool to play around and see which keywords are available

Typically I use the console a lot in the DevTool.
For exemple, in the console, type:

 currentDocument = app.activeDocument;
 layers = currentDocument.activeLayers;

then type layers[0]
.

This is what you get:
Screenshot 2021-03-04 at 14.16.53

Thanks @Pierre_G thats going to help me move forward.
On a side note, what editor do you like.
I am using a Mac and trying a few at the moment, Visual Studio Code, Atom and Sublime text

@IanBarber, that’s great!
Oh I’m on Mac too. For the past 5 years I’ve done everything with VSC. Loving it! :wink:

Inspecting the DOM classes as @Pierre_G suggested doesn’t really help in that case. These are layer properties once again.

You can read about the ActionReference class in old Docs:

image

So there isn’t much more to it, either an _enum/_value combination or _id, _index, _name or _offset. That’s all.

1 Like