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
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")
...
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?
Copy link to clipboard
Copied
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;
};
Copy link to clipboard
Copied
Thank you very much I will try it thanks again for your help
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;
}
Copy link to clipboard
Copied
Good catch!
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.
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!
Copy link to clipboard
Copied
Can you provide a file where this occurs?
Copy link to clipboard
Copied
hi
great work thank you so much for helping i am really thankful
regards
Wael Mo,
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.
Copy link to clipboard
Copied
Is it possible to do something similar using Illustrator?
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, …?
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.
Copy link to clipboard
Copied
Please provide the ai-file and the placed image.
CMYK-images have at least four Channels (additionally Spot Channels are possible).
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
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