Copy link to clipboard
Copied
I've got an image that has its color changed by a clipped mask above it. I am trying to build a script to automate this task, setting different values for the hue, saturation and lightness.
I've managed to create the following script, which creates a Hue/Saturation layer with "Colorize" checkbox enabled, however, I don't know how to initialize the hue, saturation and lightness values.
/////////////
var idMk = charIDToTypeID( "Mk " );
var desc43 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref8 = new ActionReference();
var idAdjL = charIDToTypeID( "AdjL" );
ref8.putClass( idAdjL );
desc43.putReference( idnull, ref8 );
var idUsng = charIDToTypeID( "Usng" );
var desc44 = new ActionDescriptor();
var idType = charIDToTypeID( "Type" );
var desc45 = new ActionDescriptor();
var idpresetKind = stringIDToTypeID( "presetKind" );
var idpresetKindType = stringIDToTypeID( "presetKindType" );
var idpresetKindDefault = stringIDToTypeID( "presetKindDefault" );
desc45.putEnumerated( idpresetKind, idpresetKindType, idpresetKindDefault );
var idClrz = charIDToTypeID( "Clrz" );
desc45.putBoolean( idClrz, true );
var idHStr = charIDToTypeID( "HStr" );
desc44.putObject( idType, idHStr, desc45 );
var idAdjL = charIDToTypeID( "AdjL" );
desc43.putObject( idUsng, idAdjL, desc44 );
executeAction( idMk, desc43, DialogModes.NO );
/////////////
Does anyone know how can I set those values? Thanks in advance.
I do not know if I understand correctly
maybe you're looking for something similar
...// =======================================================
var desc2 = new ActionDescriptor();
var desc3 = new ActionDescriptor();
var desc4 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putClass( charIDToTypeID( "AdjL" ));
desc2.putReference( charIDToTypeID( "null" ), ref1 );
desc4.putEnumerated( stringIDToTypeID( "presetKind" ), stringIDToTypeID( "presetKindType" ), stringIDToTypeID( "presetKindDefault
Copy link to clipboard
Copied
I do not know if I understand correctly
maybe you're looking for something similar
// =======================================================
var desc2 = new ActionDescriptor();
var desc3 = new ActionDescriptor();
var desc4 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putClass( charIDToTypeID( "AdjL" ));
desc2.putReference( charIDToTypeID( "null" ), ref1 );
desc4.putEnumerated( stringIDToTypeID( "presetKind" ), stringIDToTypeID( "presetKindType" ), stringIDToTypeID( "presetKindDefault" ));
desc4.putBoolean( charIDToTypeID( "Clrz" ), false );
desc3.putObject( charIDToTypeID( "Type" ), charIDToTypeID( "HStr" ), desc4 );
desc2.putObject( charIDToTypeID( "Usng" ), charIDToTypeID( "AdjL" ), desc3 );
executeAction( charIDToTypeID( "Mk " ), desc2, DialogModes.NO );
// =======================================================
var desc5 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ));
desc5.putReference( charIDToTypeID( "null" ), ref2 );
executeAction( charIDToTypeID( "GrpL" ), desc5, DialogModes.NO );
// =======================================================
var desc6 = new ActionDescriptor();
var desc7 = new ActionDescriptor();
var desc8 = new ActionDescriptor();
var list1 = new ActionList();
var ref3 = new ActionReference();
ref3.putEnumerated( charIDToTypeID( "AdjL" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ));
desc6.putReference( charIDToTypeID( "null" ), ref3 );
desc7.putEnumerated( stringIDToTypeID( "presetKind" ), stringIDToTypeID( "presetKindType" ), stringIDToTypeID( "presetKindCustom" ));
desc7.putBoolean( charIDToTypeID( "Clrz" ), true );
desc8.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Cmps" ));
desc8.putInteger( charIDToTypeID( "H " ), 51 ); /// HUE
desc8.putInteger( charIDToTypeID( "Strt" ), 59 ); /// SATURATION
desc8.putInteger( charIDToTypeID( "Lght" ), 0 ); /// LIGHTNESS
list1.putObject( charIDToTypeID( "Hst2" ), desc8 );
desc7.putList( charIDToTypeID( "Adjs" ), list1 );
desc6.putObject( charIDToTypeID( "T " ), charIDToTypeID( "HStr" ), desc7 );
executeAction( charIDToTypeID( "setd" ), desc6, DialogModes.NO );
Copy link to clipboard
Copied
This is very usefl. Sorry to post on an old post but I can' find the answer anywhere else.
What if I don't want to create the adjustmnent layer, but only edit its parameters?
Because I have it within a for loop and I don't need it to be re-created ecery time.
Copy link to clipboard
Copied
Try this (without colorize):
adjustHSL(-180, 50, 0);
function adjustHSL(hue, saturation, lightness) {
try {
activeDocument.activeLayer.kind == LayerKind.HUESATURATION;
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var descriptor3 = new ActionDescriptor();
var list = new ActionList();
var reference = new ActionReference();
reference.putEnumerated(s2t("adjustmentLayer"), s2t("ordinal"), s2t("targetEnum"));
descriptor.putReference(s2t("null"), reference);
descriptor3.putInteger(s2t("hue"), hue);
descriptor3.putInteger(s2t("saturation"), saturation);
descriptor3.putInteger(s2t("lightness"), lightness);
list.putObject(s2t("hueSatAdjustmentV2"), descriptor3);
descriptor2.putList(s2t("adjustment"), list);
descriptor.putObject(s2t("to"), s2t("hueSaturation"), descriptor2);
executeAction(s2t("set"), descriptor, DialogModes.NO);
} catch (e) {
//alert("The active layer isn't a Hue/Saturation adjustment layer!");
}
}
With colorize:
adjustHSLcolorize(true, 360, 50, 0);
function adjustHSLcolorize(colorize, hue, saturation, lightness) {
try {
activeDocument.activeLayer.kind == LayerKind.HUESATURATION;
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var descriptor3 = new ActionDescriptor();
var list = new ActionList();
var reference = new ActionReference();
reference.putEnumerated(s2t("adjustmentLayer"), s2t("ordinal"), s2t("targetEnum"));
descriptor.putReference(s2t("null"), reference);
descriptor2.putBoolean(s2t("colorize"), colorize);
descriptor3.putEnumerated(s2t("channel"), s2t("channel"), s2t("composite"));
descriptor3.putInteger(s2t("hue"), hue);
descriptor3.putInteger(s2t("saturation"), saturation);
descriptor3.putInteger(s2t("lightness"), lightness);
list.putObject(s2t("hueSatAdjustmentV2"), descriptor3);
descriptor2.putList(s2t("adjustment"), list);
descriptor.putObject(s2t("to"), s2t("hueSaturation"), descriptor2);
executeAction(s2t("set"), descriptor, DialogModes.NO);
} catch (e) {
//alert("The active layer isn't a Hue/Saturation adjustment layer!");
}
}
Copy link to clipboard
Copied
@RamonMazinga – how did the code that I posted work for you?
Copy link to clipboard
Copied
I don't know about Ramon, but it worked great for me.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
how does one learn logic behind this?
Copy link to clipboard
Copied
Behind what in particular – AM code?