Possible bug when getting document channels if PS is not in English?

When I run this code with Photoshop in English I can get the channels without a problem:

const channels = app.documents.getByName(docName).channels;
console.log(channels[0]);

CONSOLE RESULT:

ComponentChannel {_docId: 60, _name: "red"}

This is how the channels panel looks in English:

However when I try to run this code in Photoshop in Polish, I have an issue:
I try to run the same code:

const channels = app.documents.getByName(docName).channels;
console.log(channels[0]);

CONSOLE RESULT:

Error: Invalid ComponentChannel referenced in PSChannel

This is how the channels panell looks in Polish:

So I assume the bug is with the naming? How can we solve this? I don’t want to bruteforce the user to change PS to english to be able to use my plugin, I’m trying to get the channels dinamically but I had no luck, I can’t even get the document channels, so it might be something is not coded in the DOM?

If I log the length of channels to the console it logs 3, but cannot access to any of them, same error.

Thanks!
Mario OM

I know about this one… I wrote a fix for a DOM and it is still in the review. @samgannaway

Currently, the sad reality is that channels in DOM work only in English. All other localization will fail. Since the issue is tied with channel identity itself… there is no easy with to fix it by 3rd party.

1 Like

Oh man… I mean, we always find a way to make it to work, but the less steps the user needs to do to make our software work the better. Is there a way I can help to make this fix work? Any way we can help? There are some things about UXP that I would like to help to improve for all of us, different point of view of a problem helps to find a solution faster.

In short terms, what is the problem behind the scenes?

Internally DOM uses enum in reference. But different color modes have different enums. So you have to take it from someplace. Currently, it uses channel name and converts it into lowercase.

Qu’ils mangent de la batchPlay!

const photoshop = require('photoshop') ;
const { app } = photoshop ;
const { batchPlay } = photoshop.action ;

/**
  * get indexes for all channels of a document. 
  * not sure if indexes or indices should be used
  * @param {Number} docID target document id
  * @return {Promise<Array<Number>>}
*/
const getChannelIndexes = async (docID) => {
  const retval = await batchPlay(
    [
      {
        "_obj": "multiGet", 
        "_target": [
          {
            "_ref": "document", 
            "_id": docID
          }
        ], 
        "extendedReference": [
          [
            "itemIndex"
          ], 
          {
            "_obj": "channel", 
            "index": 1, 
            "count": -1
          }
        ], 
        "options": {
          "failOnMissingProperty": false, 
          "failOnMissingElement": false
        }, 
        "_options": {
          "dialogOptions": "dontDisplay"
        }
      }
    ], 
    
    {}
  ) ;

  const res = retval[0].list.map((item) => {return item.itemIndex}) ;
  return res ;
} ;

/**
  * get channel by index
  * @param {Number} docID target document id
  * @param {Number} index target channel index
  * @return {Promise<any>} {channelName: String, itemIndex: Number, count: Number, visible: Boolean, histogram: Array<Number>}
*/
const getChannelByIndex = async (docID, index) => {
  const retval = await batchPlay(
    [
      {
        "_obj": "get", 
        "_target": [
          {
            "_ref": "channel", 
            "_index": index
          }, 
          {
            "_ref": "document", 
            "_id": docID
          }
        ], 
        "_options": {
          "dialogOptions": "dontDisplay"
        }
      }
    ], 

    {}
  ) ;

  return retval[0] ;
}

const main = async () => {
  const docID = app.activeDocument.id ;
  const indexes = await getChannelIndexes(docID) ;
  const channels = await Promise.all(indexes.map(async (index) => {
    return await getChannelByIndex(docID, index) ;
  })) ;
  console.log(channels) ;
  // --> (3) [{…}, {…}, {…}]
} ;

3 Likes

Yes, this can help. It is not an instance of a Channel with methods. Just plain JS object instead with some data. And I think if you would have some alpha channel or layer masks there it could list them too.

DOM fix was approved so it should arrive within some of the 24.6. beta builds. Please keep in mind that this was broken since the beginning of its presence in DOM.

3 Likes

You are the MVP Jarda <3!! Thank you very much for letting us know this! I appreciate the hard work to make this a better environment for us as developers!

Thank you very much for this solution!!

1 Like

Please check the latest 24.6.0 build (m2185). Can you confirm it works as it should?

Just downaload the latest beta ( v 24.6 ) and still not working.

Tried this code:

const channels = app.activeDocument.channels;
console.log(channels[0]);

Got this:

Error: Invalid ComponentChannel referenced in PSChannel
    at PSChannel (uxp://uxp-internal/ps-app.js:1)
    at Object.get (uxp://uxp-internal/ps-app.js:1)
    at e.exports.<anonymous> (VM11 C:\Users\mario\UXP\OniricUXP\index.js:3111)
    at uxp://uxp-internal/domjs_scripts.js:2
    at Object.runWithNativeHandler (<anonymous>)
    at D (uxp://uxp-internal/domjs_scripts.js:2)
    at uxp://uxp-internal/domjs_scripts.js:2
    at L (uxp://uxp-internal/domjs_scripts.js:2)
    at P (uxp://uxp-internal/domjs_scripts.js:2)
    at e (uxp://uxp-internal/domjs_scripts.js:2)

OK, thanks. I think it is not in this build yet.

1 Like

I’ll be patiently waiting for it, thanks Jarda!