Copy link to clipboard
Copied
Hi there,
can someone probably tell me how to deactivate specific channels of a layer?
Example: Photoshop file with two layers, say CMYK. I want to deactivate CMY of the first layer, so that only K can be seen.
Unfortunately I didn’t find any information in the PS scripting guide nor in the scripting reference.
Thanks for any help on this.
andy
Copy link to clipboard
Copied
In the scripting guide, page 25 states...
Set the active channels to the first and third channel using a channel array:
set current channels of current document to ¬
{ channel 1 of current document, channel 3 of current document }
Alternatively, select all component channels using the component channels property of the Document
object.
set current channels of current document to component channels ¬
of current document
Copy link to clipboard
Copied
Hi Paul, thanks for your reply.
I know this one, but it affects the channels of the whole document, not of a single layer. I need to deactivate the magenta channel of the second layer only, for example.
Copy link to clipboard
Copied
Channels are at document level not layer level that's why you can't find anything. A work-a-round might be to duplicate the layer to a new document, do the channels adjustments and put it back?
Copy link to clipboard
Copied
Paul, is correct you can't even do this in the app through the GUI. You would either need to duplicate your top layer loop through the channels that you don't want selecting all and clearing then going back to the composite or you could add an adjustment layer above the top grouped and use this by toggling its visibility (this is the way I would go). Paul 'AppleScript'? you've made me smile this morning what's come over you…
Added some code from scriptlistener…
tell application "Adobe Photoshop CS2"
activate
set Doc_Ref to the current document
tell Doc_Ref
if mode = CMYK then
set current layer to layer 1
-- delay 2
do javascript "Just_Black(); function Just_Black() {function cTID(s) { return app.charIDToTypeID(s); }; function sTID(s) { return app.stringIDToTypeID(s); }; var desc01 = new ActionDescriptor(); var ref4 = new ActionReference(); ref4.putClass( cTID('AdjL') ); desc01.putReference( cTID('null'), ref4 ); var desc02 = new ActionDescriptor(); desc02.putBoolean( cTID('Grup'), true ); var desc03 = new ActionDescriptor(); var list5 = new ActionList(); var desc04 = new ActionDescriptor(); var ref5 = new ActionReference(); ref5.putEnumerated( cTID('Chnl'), cTID('Chnl'), cTID('Cyn ') ); desc04.putReference( cTID('Chnl'), ref5 ); var list6 = new ActionList(); var desc05 = new ActionDescriptor(); desc05.putDouble( cTID('Hrzn'), 0.000000 ); desc05.putDouble( cTID('Vrtc'), 255.000000 ); list6.putObject( cTID('Pnt '), desc05 ); var desc06 = new ActionDescriptor(); desc06.putDouble( cTID('Hrzn'), 255.000000 ); desc06.putDouble( cTID('Vrtc'), 255.000000 ); list6.putObject( cTID('Pnt '), desc06 ); desc04.putList( cTID('Crv '), list6 ); list5.putObject( cTID('CrvA'), desc04 ); var desc07 = new ActionDescriptor(); var ref6 = new ActionReference(); ref6.putEnumerated( cTID('Chnl'), cTID('Chnl'), cTID('Mgnt') ); desc07.putReference( cTID('Chnl'), ref6 ); var list7 = new ActionList(); var desc08 = new ActionDescriptor(); desc08.putDouble( cTID('Hrzn'), 0.000000 ); desc08.putDouble( cTID('Vrtc'), 255.000000 ); list7.putObject( cTID('Pnt '), desc08 ); var desc09 = new ActionDescriptor(); desc09.putDouble( cTID('Hrzn'), 255.000000 ); desc09.putDouble( cTID('Vrtc'), 255.000000 ); list7.putObject( cTID('Pnt '), desc09 ); desc07.putList( cTID('Crv '), list7 ); list5.putObject( cTID('CrvA'), desc07 ); var desc10 = new ActionDescriptor(); var ref7 = new ActionReference(); ref7.putEnumerated( cTID('Chnl'), cTID('Chnl'), cTID('Yllw') ); desc10.putReference( cTID('Chnl'), ref7 ); var list8 = new ActionList(); var desc11 = new ActionDescriptor(); desc11.putDouble( cTID('Hrzn'), 0.000000 ); desc11.putDouble( cTID('Vrtc'), 255.000000 ); list8.putObject( cTID('Pnt '), desc11 ); var desc12 = new ActionDescriptor();desc12.putDouble( cTID('Hrzn'), 255.000000 ); desc12.putDouble( cTID('Vrtc'), 255.000000 ); list8.putObject( cTID('Pnt '), desc12 ); desc10.putList( cTID('Crv '), list8 ); list5.putObject( cTID('CrvA'), desc10 ); desc03.putList( cTID('Adjs'), list5 ); desc02.putObject( cTID('Type'), cTID('Crvs'), desc03 ); desc01.putObject( cTID('Usng'), cTID('AdjL'), desc02 ); executeAction( cTID('Mk '), desc01, DialogModes.NO );}" show debugger on runtime error
end if
end tell
end tell
Copy link to clipboard
Copied
I copied it straight from the pdf, honest Mark. My AppleScript is ZERO or less
Copy link to clipboard
Copied
My JavaScript/ExtendScript is still around about the same figure!!! and mostly copied…
Copy link to clipboard
Copied
Thanks, guys. I found a different workaround via adjusting levels
Nachricht geändert durch jazzanova997
Copy link to clipboard
Copied
Actually, this can be done through the GUI. It's under the 'Advanced Blending options' for the layer, you can select or deselect certain channels.
A quick ScriptListener recording provides the following code (I added comments to show the code to activate or deactivate the 4 channels in my CMYK document):
// =======================================================
var id119 = charIDToTypeID( "setd" );
var desc23 = new ActionDescriptor();
var id120 = charIDToTypeID( "null" );
var ref13 = new ActionReference();
var id121 = charIDToTypeID( "Lyr " );
var id122 = charIDToTypeID( "Ordn" );
var id123 = charIDToTypeID( "Trgt" );
ref13.putEnumerated( id121, id122, id123 );
desc23.putReference( id120, ref13 );
var id124 = charIDToTypeID( "T " );
var desc24 = new ActionDescriptor();
var id125 = stringIDToTypeID( "channelRestrictions" );
var list5 = new ActionList();
// Cyan Channel
//var id126 = charIDToTypeID( "Chnl" );
//var id127 = charIDToTypeID( "Cyn " );
//list5.putEnumerated( id126, id127 );
// Magenta Channel
var id128 = charIDToTypeID( "Chnl" );
var id129 = charIDToTypeID( "Mgnt" );
list5.putEnumerated( id128, id129 );
// Yellow Channel
//var id130 = charIDToTypeID( "Chnl" );
//var id131 = charIDToTypeID( "Yllw" );
//list5.putEnumerated( id130, id131 );
// Black Channel
var id132 = charIDToTypeID( "Chnl" );
var id133 = charIDToTypeID( "Blck" );
list5.putEnumerated( id132, id133 );
desc24.putList( id125, list5 );
var id134 = charIDToTypeID( "Lyr " );
desc23.putObject( id124, id134, desc24 );
executeAction( id119, desc23, DialogModes.NO );
Turning off the code for a channel will disable that channel for that layer.
You should be able to turn this into a usable function with parameters for layer and channels.
Copy link to clipboard
Copied
I guess it depends on the look wanted. My first thought when I read Andy's reguest was to suggest using Apply Image to set the layer to the black channel. But I also like Mark's blending suggestion.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now