Copy link to clipboard
Copied
I can get the names of all the current channels in a document with:
But sometimes a document has multiple channels with identical names. So when I perform actions based on the channels returned this way.
Is there a way to get the indexes of every channel, rather than the names?
I also convert it into RGB.
Thanks,
Sunil
Copy link to clipboard
Copied
One work-around for multichannel-images:
// get indices of selected channels for multichannel files;
// 2022, use it at your own risk;
if (app.documents.length > 0) {
var myDocument = activeDocument;
if (myDocument.mode == DocumentMode.MULTICHANNEL) {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("numberOfChannels"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var docDesc = executeActionGet(ref);
var numberChannels = docDesc.getInteger(stringIDToTypeID("numberOfChannels"));
////////////////////////////////////
var theSelCh = myDocument.activeChannels;
var theTestName = "ignoreAndRestoreThisName"+Math.random();
var theSelectedChannelsIndices = new Array;
for (var m = 0; m < theSelCh.length; m++) {
theSelCh[m].name = theTestName;
for (var n = 0; n < numberChannels; n++) {
if (myDocument.channels[n].name == theTestName) {theSelectedChannelsIndices.push(n)}
};
executeAction( charIDToTypeID("undo"), undefined, DialogModes.NO );
};
alert ("selected channels indices\n"+theSelectedChannelsIndices.join("\n"));
}
};
Copy link to clipboard
Copied
Personally I prefer »indices« as the plural of »index« but I suspect that’s kinda pretentious.
Anyway, I failed to notice an easy access to the index of the selected Channels either in DOM and AM.
And in RGB images the renaming-work-around runs into problems with the composite channels (I expect the same for Lab and CMYK) and alpha-channels could also be named »Red«, »Green« and »Blue«, so a channel-deletion-work-around for the first three items in the array of the selected channels might be necessary.
Maybe I have overlooked something and someone else can provide an easier solution.
Copy link to clipboard
Copied
Thank you sir....