• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I get selected channel indexes?

Community Beginner ,
Jul 28, 2022 Jul 28, 2022

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

TOPICS
Actions and scripting , Windows

Views

164

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jul 30, 2022 Jul 30, 2022

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"));
}
};

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2022 Jul 30, 2022

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 08, 2022 Sep 08, 2022

Copy link to clipboard

Copied

LATEST

c.pfaffenbichler 

Thank you sir....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines