Layer and Channel strangeness

Discussion of actual or possible Photoshop Scripting Bugs, Anomalies and Documentation Errors

Moderators: Tom, Kukurykus

Mike Hale

Layer and Channel strangeness

Post by Mike Hale »

I have been working with channels and layer for a script that creates a layer mask then later changes it And I have found the following unexpected behavior.

1. If the user clicks off a layer but in the layers palette so that no layers are highlighted a JS script will return the topmost layer as activeLayer regardless of which layer was active before the click. But if you try to do almost anything with the activelayer, CS2 throws an error.

So you can't count on there always being on activeLayer methods working and I don't see a way to test for this without error checking.

2. If a layer has a mask, even if the layer is the active layer, the mask is not a channel object. At least, it not exposed.

activeDocument.channels.length returns the number of component channels plus any alpha channels. In an RGB image with only the layer mask it returns 3.

activeDocument.channels.getByName("Layer 1 Mask") throws an error.

So I don't see a way to tell if a layer already has a mask or how to load that mask as a selection, apply or discrad the mask, or turn the mask off without using scriptlistner.

3. You can only add an alpha channel to the activeChannels if there is only one layer and it is the background. Other wise you can either select just component channels or alpha channels, not both.

Has anyone else seen these things or am I doing something wrong?