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

check if channel have pixels or not script code

Explorer ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

hi i am trying to write a code that check the channel if it is contains any pixles  color information let this channel open if it is white it close the channel then go to the next channel and do the same thing tell it check all the open channels in javascript thanks for helping i have 10 channels to chek

thanks for helping

TOPICS
Windows

Views

355

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

Community Expert , Jul 12, 2022 Jul 12, 2022

Please try this: 

// 2022, use it at your own risk;
if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    var theChannels = myDocument.channels;
    var originalRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var theTotal = Number(myDocument.width) * Number(myDocument.height);
    for (var m = theChannels.length - 1; m >= 0; m--) {
        var thisChannel = theChannels[m];
        if (thisChannel.kind == "ChannelType.SPOTCOLOR") 
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

Channels (as represented in the Channels Panel) cannot be »closed«, they can be shown/hidden, deleted, … 

 

Could you please post screenshots with the pertinent Panels (Toolbar, Layers, Challens, Options Bar, …) visible to clarify what you are trying to achieve? 

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
Explorer ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

  • Delete the empty  channel 
  • 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 ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

 

// 2022, use it at your own risk;
if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    var theChannels = myDocument.channels;
    var originalRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var theTotal = Number(myDocument.width) * Number(myDocument.height);
    for (var m = 0; m < theChannels.length; m++) {
        var thisChannel = theChannels[m];
        thisChannel.visible = true;
        var theHisto = thisChannel.histogram;
        if (theHisto[255] == theTotal) {
            thisChannel.visible = false;
            thisChannel.remove()
        };
    };
    app.preferences.rulerUnits = originalRulerUnits;
};

 

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
Explorer ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

Thank you very much I will try it thanks again for your help 

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 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

@c.pfaffenbichler – great work as always!

 

As it was only confirmed after your script was posted that the intent was to remove spot channels, I have added a conditional for that to your code, which retains white alphas.

 

// 2022, use it at your own risk;
if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    var theChannels = myDocument.channels;
    var originalRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var theTotal = Number(myDocument.width) * Number(myDocument.height);
    for (var m = 0; m < theChannels.length; m++) {
        var thisChannel = theChannels[m];
        thisChannel.visible = true;
        var theHisto = thisChannel.histogram;
        if (theHisto[255] == theTotal) {
            thisChannel.visible = false;
            if (thisChannel.kind == "ChannelType.SPOTCOLOR") {
                thisChannel.remove();
            }
        } else {
            thisChannel.visible = true;
        }
    }
    app.preferences.rulerUnits = originalRulerUnits;
}

 

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 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

Good catch! 

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
Explorer ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

hello sir

thanks very much for this code but i have problem when i use it it dose not remove all the  spot channels that  have not any pixels from the first time i must run this script more than twice to remove all the empty  spot channels thanks again for your time

regards

Wael Mo.

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 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

I don't know what the problem is, the following hopefully short-term hack runs the script 5 times...

 

Edit: I have removed the hack so as not to confuse things now that it has been fixed!

 

 

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 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

Can you provide a file where this occurs? 

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
Explorer ,
Jul 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

hi

great work thank you so much for helping i am really thankful 

regards

Wael Mo,

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 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

Please try this: 

// 2022, use it at your own risk;
if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    var theChannels = myDocument.channels;
    var originalRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var theTotal = Number(myDocument.width) * Number(myDocument.height);
    for (var m = theChannels.length - 1; m >= 0; m--) {
        var thisChannel = theChannels[m];
        if (thisChannel.kind == "ChannelType.SPOTCOLOR") {
            thisChannel.visible = true;
            var theHisto = thisChannel.histogram;
            if (theHisto[255] == theTotal) {
                thisChannel.visible = false;
                thisChannel.remove()
            } else {
                thisChannel.visible = true
            }
        }
    };
    app.preferences.rulerUnits = originalRulerUnits;
};

 

Such a simple mistake … 

I »counted« up instead of down. 

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 ,
Apr 01, 2024 Apr 01, 2024

Copy link to clipboard

Copied

Is it possible to do something similar using Illustrator?

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 ,
Apr 01, 2024 Apr 01, 2024

Copy link to clipboard

Copied

I would recommend that you post on the Illustrator Forum, but be more specific than »something similar«. 

What exactly are you trying to check – PathItems, Layers, placed images, …? 

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 ,
Apr 01, 2024 Apr 01, 2024

Copy link to clipboard

Copied

I'm trying to find a way to find out if an image contains cyan or magenta, for example, because even though these colors don't exist in the image, when I check the number of channels, four always appear.

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 ,
Apr 01, 2024 Apr 01, 2024

Copy link to clipboard

Copied

LATEST

Please provide the ai-file and the placed image. 

CMYK-images have at least four Channels (additionally Spot Channels are possible). 

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 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

Is this needed for 10 alpha channels?

 

Or is this needed for C, M, Y, K + 6 alpha and or spot channels etc?

 

Do you want to be notified one channel at a time, or have a single list of channels notifications at the end?

 

Is this something that you wish to do while the document is being worked on, further steps taken after running the script, or would a batch be better so that you can process many files and then read a log to see which files pass/fail etc?

 

The following code is broken due to the change in forum software or later versions of Photoshop working differently, however, it would be a good start:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/remove-empty-channel/td-p/2448887

 

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
Explorer ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

Hi 

I need it for spot channel  10 spot channel  deleted  the empty channel  and leaves  the other spot channel 

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