Can't create a new channel using batchPlay with API 2

Using API 1, I was able to create a new channel on the Channels panel in Photoshop with the following code from Alchemist:

await require('photoshop').action.batchPlay([
        // Create a new channel
        {"_obj": "make","new": {"_obj": "channel","colorIndicates": {"_enum": "maskIndicator","_value": "maskedAreas"},"color": {"_obj": "RGBColor","red": 255,"grain": 0,"blue": 0},"opacity": 50}},
    ], { "synchronousExecution": false, "modalBehavior": "wait" })

With API 2 inside a targetFunction called with executeAsModal , I use the following code and nothing happens.

await require('photoshop').action.batchPlay([
        // Create a new channel
        {"_obj": "make","new": {"_obj": "channel","colorIndicates": {"_enum": "maskIndicator","_value": "maskedAreas"},"color": {"_obj": "RGBColor","red": 255,"grain": 0,"blue": 0},"opacity": 50}},
    ], {})

Is this a bug with API 2 or am I doing something wrong?

In API 2, the result in the debugger shows:

debugger

So it looks like the code executes just fine. I just doesn’t create a new channel on the Channels panel.

Of note, I also tried using the Alchemist-generated code for using calculations to create a new channel and get the same result. The code executes according to the debugger, but no new channel is created on the Channels panel.

I wonder if being in a modal state prevents new channels from being created and if so what the workaround is for creating them.

I think you need “modalBehavior: execute” or how it is called.

I tried:

await require('photoshop').action.batchPlay([
            // Create a new channel
            {"_obj": "make","new": {"_obj": "channel","colorIndicates": {"_enum": "maskIndicator","_value": "maskedAreas"},"color": {"_obj": "RGBColor","red": 255,"grain": 0,"blue": 0},"opacity": 50}},
        ], { "modalBehavior": "execute" });

Same result. No new channel on the Channels panel. The weird part is that the debugger read-out shows successful execution, but there is no new channel on the Channels panel.

What is your color mode and number of layers?

RGB Color mode for the images and various numbers of layers. I’ve tried it on multiple images from one Background layer to five or six layers. Always the same thing. Debugger shows the code resolved w/o errors but the Channels panel shows no new channel. I use a Windows computer with Ps 23.1.1 and Ps beta 23.2.0. I’ve tried both these versions with the same results.

The Alchemist code for duplicating a channel doesn’t work in API 2 either:

await require('photoshop').action.batchPlay([
            {
   "_obj": "duplicate",
   "_target": [
      {
         "_ref": "channel",
         "_enum": "channel",
         "_value": "blue"
      }
   ],
   "_isCommand": true
}
        ], {})

Figured it out. I had this batchPlay inside as suspendHistory() function. Once this function was removed, then everything worked fine. I don’t know why creating and duplicating channels within the suspendHistory() function doesn’t work, but it doesn’t appear to.

1 Like

As far as I know suspendHistory() is not supported within UXP code. Check this link for the new solution: https://www.adobe.io/photoshop/uxp/2022/ps_reference/media/executeasmodal/#history-state-suspension

@Dominik_S, yes, that’s what I meant. Some batchPlay doesn’t work inside History State Suspension.

I’ve also found that some batchPlay will run inside History State Suspension, but the history state “name” will NOT be captured on the History panel. Specifically:

await require('photoshop').action.batchPlay([
            //Load RGB channel as a selection
            { "_obj": "set", "_target": [{"_ref": "channel", "_property": "selection"}], "to": {"_ref": "channel","_enum": "channel","_value": "RGB"}}
        ], {});

Running that code inside the History State Suspension with "name": "Selection" results in nothing showing up on the History panel. But if I add another step to the batchPlay, like turning a layer’s visibility on or off, then the “name” appropriately appears on the History panel. My initial evaluation is that things that involve the Channels panel don’t always work well inside History State Suspension.

Just tested it and I can confirm this - it doesn’t show a history step for me either.
Done manually (clicking the UI) it does log a history entry though, so there really seems to be some UXP / internal issue related to some descriptors.