Script To Select All Channels?

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

Colorguy

Script To Select All Channels?

Post by Colorguy »

I've been looking into doing a script that simply selects all alpha/spot channels and can't figure it out. Needs to select them all regardless of name or number of channels.

Edit:

So, I figured out the following will select all the component channels. Still trying to work out how to also select "all" the Spot or Alpha channels.

Code: Select allapp.activeDocument.activeChannels =
activeDocument.componentChannels

Edit 2

Well, here's how to delete all Spot or Alpha channels. Still can't figure out how to select them all?

Code: Select allapp.bringToFront();
var theImage = app.activeDocument;
theImage.channels.removeAll();

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

larsen67

Script To Select All Channels?

Post by larsen67 »

Active channels will expect an array I think. So you would need to check the document color mode first then count the non-component channels… So using the indexes

Code: Select allvar doc = app.activeDocument;

doc.activeChannels = [doc.channels[4],doc.channels[5]];

Would select the 5th & 6th channels… but they would need to exist…
Colorguy

Script To Select All Channels?

Post by Colorguy »

Yes, that wouldn't work since the document would need to contain the exact number of Channels the script is targeting. The way I see it, if a simple script can be written to delete all channels regardless of number, then one can surely be done which selects all channels. Been working on this all day and still can't figure it out. Although I admit to being a novice at the moment.
Mike Hale

Script To Select All Channels?

Post by Mike Hale »

ActiveChannels is the way to select the channels. You just have to look through the channels and store the ones you want to select in an array.

Code: Select allvar channelArray = [];
for(var c = 0; c < app.activeDocument.channels.length;c++ ){
   if( (app.activeDocument.channels[c].kind == ChannelType.SPOTCOLOR) || (app.activeDocument.channels[c].kind == ChannelType.MASKEDAREA) ){
      channelArray.push( app.activeDocument.channels[c] );
   }
}
app.activeDocument.activeChannels =  channelArray;
Colorguy

Script To Select All Channels?

Post by Colorguy »

Can't thank you enough Mike. Would have been struggling with that one forever. There was more to it than I originally thought.
larsen67

Script To Select All Channels?

Post by larsen67 »

Mike, I would have done this the other way over… or did I miss something…?

Code: Select allvar channelArray = [];

for ( var c = app.activeDocument.channels.length-1; c >= 0; c-- ) {

   if ( app.activeDocument.channels[c].kind != ChannelType.COMPONENT ) {
   
      channelArray.push( app.activeDocument.channels[c] );
   }
}

app.activeDocument.activeChannels =  channelArray;

Not sure if its worth breaking out at first component?
Mike Hale

Script To Select All Channels?

Post by Mike Hale »

I'm not sure it makes much difference which order the channels are tested. But as long as the loop starts at the bottom of the channel stack I think I would add the break.