skip to Main Content

So I’m new to Photoshop Scripting, but have a solid grasp of JS.

I’m trying to make a selection based on the ‘RGB’ channel, but my code is erroring, saying “No such element”. How can I load the RGB channel in the same way as the individual Red, Green, or Blue channels? If I replace RGB with Red, everything works perfectly.

var doc = app.activeDocument;
var currentLayer = doc.activeLayer;
var channelRef = doc.channels.getByName("RGB");
doc.selection.load(channelRef, SelectionType.REPLACE);

To clarify, I want the same functionality as clicking the ‘Channel to Selection’ icon in the channels panel with all channels selected.

2

Answers


  1. Chosen as BEST ANSWER

    I worked out the answer - record the action and copy the script it outputs. Helpful for anyone else needing to do this.

    function selectRGBChannel() {
        var idsetd = charIDToTypeID( "setd" );
        var desc3343 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref101 = new ActionReference();
            var idChnl = charIDToTypeID( "Chnl" );
            var idfsel = charIDToTypeID( "fsel" );
            ref101.putProperty( idChnl, idfsel );
        desc3343.putReference( idnull, ref101 );
        var idT = charIDToTypeID( "T   " );
            var ref102 = new ActionReference();
            var idChnl = charIDToTypeID( "Chnl" );
            var idChnl = charIDToTypeID( "Chnl" );
            var idRGB = charIDToTypeID( "RGB " );
            ref102.putEnumerated( idChnl, idChnl, idRGB );
        desc3343.putReference( idT, ref102 );
    executeAction( idsetd, desc3343, DialogModes.NO );
    };
    

  2. There is no RGB channel, by definition. You probably want an array of the three color channels:

    var channelRef = [doc.channels.getByName('Red'),doc.channels.getByName('Green'),doc.channels.getByName('Blue')];
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search