Copy link to clipboard
Copied
I try to create script which will check what is the kind of selected channel and based of that alert user, but i always got same message. Could someone help me with this code?
var myChannel = app.activeDocument.activeChannels;
if (myChannel.kind == "ChannelType.MASKEDAREA"||myChannel.kind == "ChannelType.SELECTEDAREA"||myChannel.kind == "ChannelType.SPOTCOLOR") {
alert("It is not CMYK")
}
else{
alert("It is CMYK")
}
The plural »activeChannels« should be a give-away.
Try inserting
alert (myChannel.constructor);
to see what myChannel actually is.
Yes, as rightly noted @c.pfaffenbichler app.activeDocument.activeChannels is an array. It contains one or more elements (depending on the number of dedicated channels). That is, you need to either perform a check on all elements of this array in a loop, or (if you are sure that only one channel is selected) you can use it like this:
var myChannel = app.activeDocument.activeChannels.shift();
Copy link to clipboard
Copied
The plural »activeChannels« should be a give-away.
Try inserting
alert (myChannel.constructor);
to see what myChannel actually is.
Copy link to clipboard
Copied
Yes, as rightly noted @c.pfaffenbichler app.activeDocument.activeChannels is an array. It contains one or more elements (depending on the number of dedicated channels). That is, you need to either perform a check on all elements of this array in a loop, or (if you are sure that only one channel is selected) you can use it like this:
var myChannel = app.activeDocument.activeChannels.shift();
Copy link to clipboard
Copied
Thanks guys
Copy link to clipboard
Copied
Dear @c.pfaffenbichler @jazz-y is it possible somehow (with some if statement) to check is it currently selected one or multiply channels? THanks in advance
Copy link to clipboard
Copied
Check whether the length of
app.activeDocument.activeChannels
is equal to 1 with an if-clause.
Copy link to clipboard
Copied
Thanks, i tried this and it works
var myActiveDoc = app.activeDocument;
var myChannels = myActiveDoc.activeChannels;
var total = myChannels.length;
if(total>1){
alert("multiply channels are selected")
}
else {
alert("single channel is selected")
}
Copy link to clipboard
Copied
But now i stuck again, when i selected some mask which is applied on some adjustment layer (curves, channel mixer,..) and when i run this script i got an error. Is it possible to improve this?
Copy link to clipboard
Copied
You could wrap the whole thing in a try-clause and in the catch alert that a Layer Mask is selected.
To me at least no other reason comes to mind for activeChannels erroring, it seeems impossible to have 0 Channels selected in an open document.
Copy link to clipboard
Copied
You are right, i resolved with try/catch clause, thanks for idea