Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Select all channels in multichannel mode with script

Contributor ,
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

141

Likes

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

Adobe Community Professional , 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

Likes

Translate

Translate
Adobe Community Professional ,
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.

Likes

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
Contributor ,
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]);
    }
}
}

Likes

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 Professional ,
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?

 

 

 

Likes

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
Contributor ,
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.

Likes

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 Professional ,
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

Likes

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
Contributor ,
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?

Likes

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 Professional ,
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

Likes

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

Copy link to clipboard

Copied

Great! Thanks!

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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

Likes

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
Contributor ,
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

Likes

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