Help With Including Curves Changes In Script
I thought I had mastered this but it turns out I haven't.
The ScriptListner does not appear to record the point plotted in a curves adjustment layer.
Any help appreciated
Ian
I thought I had mastered this but it turns out I haven't.
The ScriptListner does not appear to record the point plotted in a curves adjustment layer.
Any help appreciated
Ian
The above code appears to work fine if the open document is in RGB but does not work if the open document is in grayscale mode.
Can anyone throw any light on as to why that would be ?
ian
Hey ian-barber, you're right. I missed the fact that different document modes require a different charID. Here's the updated function which will work on any document mode. I'm pretty sure I covered all of them, including all possible monotone / duotone / tritone / quadtone options.
// Examples
var point1 = [28, 0];
var point2 = [37, 90];
var point3 = [163, 155];
var point4 = [253, 190];
// Add points to array
var points = [point1, point2, point3, point4];
// Execute
modifySelectedCurvesLayer(points);
/*
* @param {Array} points
* --> forEach : [x, y]
*/
function modifySelectedCurvesLayer(points) {
// Validate input
if(points.length < 2) {
alert('Curves need a minimum of 2 points');
return false;
}
// Analyze document mode
switch(app.activeDocument.mode.toString()) {
case "DocumentMode.RGB":
case "DocumentMode.CMYK":
var docModeCharID = "Cmps";
break;
case "DocumentMode.GRAYSCALE":
var docModeCharID = "Blck";
break;
case "DocumentMode.DUOTONE":
var channelName = app.activeDocument.channels[0].name;
if( channelName == "Monotone" ) {
var docModeCharID = "Mntn";
} else if( channelName == "Duotone" ) {
var docModeCharID = "Dtn ";
} else if( channelName == "Tritone" ) {
var docModeCharID = "Trtn";
} else if( channelName == "Quadtone" ) {
var docModeCharID = "Qdtn";
}
break;
case "DocumentMode.LAB":
var docModeCharID = "Lght";
break;
default:
break;
}
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "AdjL" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
var curvesLayerDesc = new ActionDescriptor();
curvesLayerDesc.putEnumerated( stringIDToTypeID( "presetKind" ), stringIDToTypeID( "presetKindType" ), stringIDToTypeID( "presetKindCustom" ) );
var chnlList = new ActionList();
var chnlDesc = new ActionDescriptor();
var channelRef = new ActionReference();
channelRef.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( docModeCharID ) );
chnlDesc.putReference( charIDToTypeID( "Chnl" ), channelRef );
var pointsList = new ActionList();
for(var i = 0; i < points.length; i++) {
var pointDesc = new ActionDescriptor();
pointDesc.putDouble( charIDToTypeID( "Hrzn" ), points[0] );
pointDesc.putDouble( charIDToTypeID( "Vrtc" ), points[1] );
pointsList.putObject( charIDToTypeID( "Pnt " ), pointDesc );
}
chnlDesc.putList( charIDToTypeID( "Crv " ), pointsList );
chnlList.putObject( charIDToTypeID( "CrvA" ), chnlDesc );
curvesLayerDesc.putList( charIDToTypeID( "Adjs" ), chnlList );
desc.putObject( charIDToTypeID( "T " ), charIDToTypeID( "Crvs" ), curvesLayerDesc );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.