Skip to main content
wael mohammedt42523860
Known Participant
July 11, 2022
Answered

check if channel have pixels or not script code

  • July 11, 2022
  • 2 replies
  • 1335 views

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

This topic has been closed for replies.
Correct answer c.pfaffenbichler

hi

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

regards

Wael Mo,


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. 

2 replies

Stephen Marsh
Community Expert
Community Expert
July 11, 2022

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

 

wael mohammedt42523860
Known Participant
July 11, 2022

Hi 

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

Thanks

 

c.pfaffenbichler
Community Expert
Community Expert
July 11, 2022

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? 

wael mohammedt42523860
Known Participant
July 11, 2022
  • Delete the empty  channel 
  • Thanks 
c.pfaffenbichler
Community Expert
Community Expert
July 11, 2022

 

// 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;
};