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

create a adjustment layer using javascript and change value for separate color in separate channel.

Community Beginner ,
Dec 01, 2023 Dec 01, 2023

// Create a new group named "A1"
var group = app.activeDocument.layerSets.add();
group.name = "A1";

// Set the document color mode to CMYK
app.activeDocument.mode = DocumentMode.CMYK;
createChannelMixerAdjustmentLayer();

// Function to create a Channel Mixer adjustment layer
function createChannelMixerAdjustmentLayer() {
// Create a new adjustment layer
var desc18 = new ActionDescriptor();
var desc19 = new ActionDescriptor();
var desc20 = new ActionDescriptor();
var ref8 = new ActionReference();
ref8.putClass(charIDToTypeID("AdjL"));
desc18.putReference(charIDToTypeID("null"), ref8);
desc20.putEnumerated(stringIDToTypeID("presetKind"), stringIDToTypeID("presetKindType"), stringIDToTypeID("presetKindDefault"));

// CMYK values
var idCyn = charIDToTypeID("Cyn ");
var desc674 = new ActionDescriptor();
desc674.putUnitDouble(idCyn, charIDToTypeID("#Prc"), 80.000000); // Set to 80%
var idChMx = charIDToTypeID("ChMx");
desc20.putObject(idCyn, idChMx, desc674);

var idMgnt = charIDToTypeID("Mgnt");
var desc675 = new ActionDescriptor();
desc675.putUnitDouble(idMgnt, charIDToTypeID("#Prc"), 60.000000); // Set to 60%
desc20.putObject(idMgnt, idChMx, desc675);

var idYlw = charIDToTypeID("Ylw ");
var desc676 = new ActionDescriptor();
desc676.putUnitDouble(idYlw, charIDToTypeID("#Prc"), 70.000000); // Set to 70%
desc20.putObject(idYlw, idChMx, desc676);

var idBlck = charIDToTypeID("Blck");
var desc677 = new ActionDescriptor();
desc677.putUnitDouble(idBlck, charIDToTypeID("#Prc"), 50.000000); // Set to 50%
desc20.putObject(idBlck, idChMx, desc677);

desc19.putObject(charIDToTypeID("Type"), charIDToTypeID("ChnM"), desc20);
desc18.putObject(charIDToTypeID("Usng"), charIDToTypeID("AdjL"), desc19);
executeAction(charIDToTypeID("Mk "), desc18, DialogModes.NO);

}


this is my code, but in this code only change same channel with same color, but i want change in
cyan channel, color value cyan=100, magenta=10, yellow=25, black=2
magenta channel, color value cyan=45, magenta=100, yellow=2, black=1
yellow channel, color value cyan=3, magenta=10, yellow=85, black=-2
black channel, color value cyan=-5, magenta=6, yellow=0, black=100


if any have solution please help me to solve my problem and if you have better solution please help me.

thank you.

TOPICS
macOS , Windows
753
Translate
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 , Dec 02, 2023 Dec 02, 2023

@ART CORNER 

 

Try this:

 

#target photoshop

// Create a new group named "A1"
var group = app.activeDocument.layerSets.add();
group.name = "A1";
// Set the document color mode to CMYK
app.activeDocument.mode = DocumentMode.CMYK;
// Function to create a Channel Mixer adjustment layer
makeChaMix();
// Function to set the Channel Mixer adjustment layer CMYK values
setChaMix();


///// FUNCTIONS /////

function makeChaMix() {
    var idmake = stringIDToTypeID("make");
    var desc793 = new ActionDe
...
Translate
Adobe
Community Expert ,
Dec 02, 2023 Dec 02, 2023
LATEST

@ART CORNER 

 

Try this:

 

#target photoshop

// Create a new group named "A1"
var group = app.activeDocument.layerSets.add();
group.name = "A1";
// Set the document color mode to CMYK
app.activeDocument.mode = DocumentMode.CMYK;
// Function to create a Channel Mixer adjustment layer
makeChaMix();
// Function to set the Channel Mixer adjustment layer CMYK values
setChaMix();


///// FUNCTIONS /////

function makeChaMix() {
    var idmake = stringIDToTypeID("make");
    var desc793 = new ActionDescriptor();
    var idnull = stringIDToTypeID("null");
    var ref89 = new ActionReference();
    var idcontentLayer = stringIDToTypeID("contentLayer");
    ref89.putClass(idcontentLayer);
    desc793.putReference(idnull, ref89);
    var idusing = stringIDToTypeID("using");
    var desc794 = new ActionDescriptor();
    var idtype = stringIDToTypeID("type");
    var idchannelMixer = stringIDToTypeID("channelMixer");
    desc794.putClass(idtype, idchannelMixer);
    var idcontentLayer = stringIDToTypeID("contentLayer");
    desc793.putObject(idusing, idcontentLayer, desc794);
    executeAction(idmake, desc793, DialogModes.NO);
}

function setChaMix() {
    cTID = function (s) {
        return app.charIDToTypeID(s);
    }
    sTID = function (s) {
        return app.stringIDToTypeID(s);
    }
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('AdjL'), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    var desc2 = new ActionDescriptor();
    desc2.putEnumerated(sTID("presetKind"), sTID("presetKindType"), sTID("presetKindCustom"));
    var C = new ActionDescriptor();
    C.putUnitDouble(cTID('Cyn '), cTID('#Prc'), 100);
    C.putUnitDouble(cTID('Mgnt'), cTID('#Prc'), 10);
    C.putUnitDouble(cTID('Ylw '), cTID('#Prc'), 25);
    C.putUnitDouble(cTID('Blck'), cTID('#Prc'), 2);
    desc2.putObject(cTID('Cyn '), cTID('ChMx'), C);
    var M = new ActionDescriptor();
    M.putUnitDouble(cTID('Cyn '), cTID('#Prc'), 45);
    M.putUnitDouble(cTID('Mgnt'), cTID('#Prc'), 100);
    M.putUnitDouble(cTID('Ylw '), cTID('#Prc'), 2);
    M.putUnitDouble(cTID('Blck'), cTID('#Prc'), 1);
    desc2.putObject(cTID('Mgnt'), cTID('ChMx'), M);
    var Y = new ActionDescriptor();
    Y.putUnitDouble(cTID('Cyn '), cTID('#Prc'), 3);
    Y.putUnitDouble(cTID('Mgnt'), cTID('#Prc'), 10);
    Y.putUnitDouble(cTID('Ylw '), cTID('#Prc'), 85);
    Y.putUnitDouble(cTID('Blck'), cTID('#Prc'), -2);
    desc2.putObject(cTID('Ylw '), cTID('ChMx'), Y);
    var K = new ActionDescriptor();
    K.putUnitDouble(cTID('Cyn '), cTID('#Prc'), -5);
    K.putUnitDouble(cTID('Mgnt'), cTID('#Prc'), 6);
    K.putUnitDouble(cTID('Ylw '), cTID('#Prc'), 0);
    K.putUnitDouble(cTID('Blck'), cTID('#Prc'), 100);
    desc2.putObject(cTID('Blck'), cTID('ChMx'), K);
    desc1.putObject(cTID('T   '), cTID('ChnM'), desc2);
    executeAction(cTID('setd'), desc1, DialogModes.NO);
}

 

 

Translate
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