Script Listener - Passing a channel (and not its name)

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Squis

Script Listener - Passing a channel (and not its name)

Post by Squis »

I recorded applying the filter "Lighting Effects" and copied and pasted the resulting code into my script, replacing the parameters with variables. This works perfectly well, except for the selection of the channel, which looks like this:

Code: Select allvar idBmpC = charIDToTypeID( "BmpC" );
var ref20 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
ref20.putName( idChnl, "Alpha 1" );
desc35.putReference( idBmpC, ref20 );

I try to avoid referring to layers and channels by name (in this case "Alpha 1"), since they're not necessarily unique, but I don't know how to pass a channel (instanceof Channel) instead of its name (instanceof String) in this syntax. Any idea?
xbytor

Script Listener - Passing a channel (and not its name)

Post by xbytor »

If you know the index of the channel, you may be able to do this instead of putting the name:

Code: Select allref20.putIndex( idChnl, 1);

I haven't tested this, however...
Mike Hale

Script Listener - Passing a channel (and not its name)

Post by Mike Hale »

Just to add to X's post. Action Manager( scriptlistener ) does not and can not use DOM objects so you can't pass a DOM channel reference to an Action Manager function. You can often use index instead of name but the index may not be the same as the DOM's index of that channel or layer.

For example even though a channel mask shows in the channel panel with a layer with a channel mask is active you can not select the mask by index with Action Manager. You also can't select the composite ( RGB, CNYK, etc ) channel by index.
Squis

Script Listener - Passing a channel (and not its name)

Post by Squis »

Ah well, the name will probably do for my purposes. Thanks, anyway!