How to read color values of the current channels?


Running app.activeDocument.activeChannels.forEach(h => console.log(h.color)); returns

​ Uncaught Error: The operation is not valid for channels of type component.
    at CompositeChannel.get (uxp://uxp-internal:1)
    at eval (VM969 Demos.jsx:14)
    at Array.forEach (<anonymous>)
    at Demos (VM969 Demos.jsx:14)
    at renderWithHooks (VM960 react-dom.development.js:14803)
    at mountIndeterminateComponent (VM960 react-dom.development.js:17482)
    at beginWork (VM960 react-dom.development.js:18596)
    at e.exports.callCallback (VM960 react-dom.development.js:188)
    at uxp://uxp-internal/domjs_scripts.js:2
    at I (uxp://uxp-internal/domjs_scripts.js:2)

What am I missing here?

Is it UXP you are talking about? I don’t see in the docs activeChannels for document at all :thinking: How did you find it?

Also, is it just console.log(h.color)? I see error comes when you try to eval() something in Demo.jsx

Yes its UXP for photoshop, its there in properties activeChannels. I don’t understand what you mean by eval() something ?

name is accessible but not color

I keep forgetting how bad docs are :man_facepalming:
Checked the right side and there’s only saveAs. Didn’t even notice the second Properties item in the menu :frowning:

Anyway… What if you try to access specific color representation? Eg. .color.rgb or .color.cmyk?

Based on this How to get access to pixel data of the active layer? - #20 by Denyoze discussion, does not look like its accessible.

Make sure that you use API version 2 on your manifest file.
Here is info about this.
Also, I found that for basic channels (RGM or CMYK) = “CompositeChannel” this doesn’t work.