layerID value is ignored in batchplay calls

,

Hello,
I have built a simple test case that shows the layerID value doesn’t get used during an _obj of ‘select’ type. If you have two layers with the same name and you use this function, the ID will be ignored, and it will always select the layer with the smallest ID.

The select function:

async function selectLayerByID (executionContext, name = 'Weathering', id = 1573) {
  console.warn('currently selected: ' + app.activeDocument.activeLayers[0].id)
  console.warn('going to select ' + String(id))
  await batchPlay(
    [
      {
        _obj: 'select',
        _target: [{ _name: name, _ref: 'layer' }],
        layerID: [id],
        makeVisible: true
      }
    ],
    {}
  )
  console.warn('currently selected: ' + app.activeDocument.activeLayers[0].id)
}

The callback function:

async function callback(){
await executeAsModal(selectLayerByID)
}

How to Repro:

  1. hookup the callback function to a button
  2. have at least three layers (Group layers show it too)
  3. give two layers the name ‘Weathering’. give one a unique name.
  4. in the selectLayerByID function, set the default for the ‘id’ parameter to be an ID for one of the duplicate layers.
  • You can get this by just running the function once and the current selected layer’s id will be sent to the log. (notice that one of the weathering layers is selected when you run the function, even though the default ID provided is probably not correct since its a random number I gave you)
  1. Remember which layer whose ID you chose for the parameter.
  2. select the unique named layer.
  3. click the button.
  4. If the expected layer was selected, swap the id parameter for the other layer.

Result:
the layer ID parameter is ignored. Instead, always 1 specific layer is selected

This ID is only for listening to events. To let you know ID of layer selected by user. When you replay this it will be useless. Instead you should pass ID in _target

1 Like

Thank you Jarda!

Per your instructions, the format that works is the following.
For others who come here, note that you pass in the id number as an int, and not a string or an array.

      {
        _obj: 'select',
        _target: [{ _name: name, _ref: 'layer', _id: 3 }],
        makeVisible: true
      }

I am struggling with trusting this API, but so far I continue to be proven wrong again and again. I truly appreciate the more knowledgeable devs showing up to clarify things each time, and I hope my overzealous posting is helpful to others who are as perplexed by this system as myself. :heart:

1 Like

To make it reliable it should be without _name just _id is good enough.