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

Select all channels in multichannel mode with script

Engaged ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

I have some script which change image mode to multichannel and select all channels, code works fine, but when it is par of some function i get some error alert. What could be a problem?

////// change to multichanel/////
var idCnvM = charIDToTypeID( "CnvM" );
var desc1639 = new ActionDescriptor();
var idT = charIDToTypeID( "T   " );
var idMltC = charIDToTypeID( "MltC" );
desc1639.putClass( idT, idMltC );
executeAction( idCnvM, desc1639, DialogModes.NO );

/////////// SELECT ALL CHANNELS///////
var myActiveDoc = app.activeDocument;
var myChannels = myActiveDoc.channels;
var total = myChannels.length;
var ac = new Array();
run();
function run() {
selectChannels();
app.activeDocument.activeChannels = this.ac;
}
function selectChannels() {
    for(var i = (total-1); i >= 0; i--){
            this.ac.push(myActiveDoc.channels[i]);
    }
}

 

Screenshot 2021-08-12 at 11.38.48.png

TOPICS
Actions and scripting , macOS , SDK

Views

675

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

correct answers 1 Correct answer

Guide , Aug 12, 2021 Aug 12, 2021

I'm not at the computer to check, but it seems when you paste this code inside another function the scope of "this.ac" changes. Remove keyword "this." everywhere. In this case the "ac" variable will be scoped to the parent function and will be available to the run () and selectChannels () subfunctions

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

Your code ran OK for me.

 

Simply converting to MC mode results in all colour channels being selected, so isn't the second part of the code redundant? Or are there spot channels or alpha channels that also need to selected after the MC mode conversion.

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
Engaged ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

Your code also works fine, but if i put in simple function like this, i got the same error as I mentioned in post.

 

selectchannels()
function selectchannels(){
////// change to multichanel/////
var idCnvM = charIDToTypeID("CnvM");
var desc1639 = new ActionDescriptor();
var idT = charIDToTypeID("T   ");
var idMltC = charIDToTypeID("MltC");
desc1639.putClass(idT, idMltC);
executeAction(idCnvM, desc1639, DialogModes.NO);

/////////// SELECT ALL CHANNELS///////
var myActiveDoc = app.activeDocument;
var myChannels = myActiveDoc.channels;
var total = myChannels.length;
var ac = [];
selectChannels();
app.activeDocument.activeChannels = this.ac;
function selectChannels() {
    for (var i = (total - 1); i >= 0; i--) {
        this.ac.push(myActiveDoc.channels[i]);
    }
}
}

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 ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

RGB or CMYK to MC mode results in all channels being selected.

 

I removed that previous code as I found that it didn't work in isolation, even if no error was triggered.

 

So again, why the second half of the code, if the first half results in all previous colour channels being selected?

 

 

 

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
Engaged ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

Because I have to choose all spot colors. If I change only the mode, only CMYK channels are selected, not spot colors. sorry for skipping to answer that question earlier.

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 ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

I have been looking for examples of scripts to select all spot channels, however they don't appear to work in CC 2021:

 

how select all spot channel by javascript

 

Select All Spot Channels In Photoshop

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
Engaged ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

This does not work in my PS ☹️ and i stil have doubt why my code does not work in function?

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
Guide ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

I'm not at the computer to check, but it seems when you paste this code inside another function the scope of "this.ac" changes. Remove keyword "this." everywhere. In this case the "ac" variable will be scoped to the parent function and will be available to the run () and selectChannels () subfunctions

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
Engaged ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

Great! Thanks!

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 ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

@jazz-y – thank you and great job as usual!

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
LEGEND ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

Where have you found this script that is uses 'this'?

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
Engaged ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

LATEST

@Kukurykus You can found on the second link posted by @Stephen_A_Marsh 

I think i also found on Git earlier

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