Skip to main content
Inspiring
March 13, 2013
Answered

Help with opening levels dialog and saving entered settings.

  • March 13, 2013
  • 1 reply
  • 1881 views

Hey,

I am trying to work out how to save the applied midpoint, whitepoint ect to a variable after the levels dialog has been called from javascript?

I am writing a script that will allow you to set the levels on one image and then I need to repeatedly apply those settings on a batch of specified images.

Is this possible? I figured out how to open and apply the levels but not save the entered settings.

Any help would be much appreciated!

I am using photoshop cs6 on a mac.

Thanks,

Mark

This topic has been closed for replies.
Correct answer Michael_L_Hale

Sorry no, it seems that those are the only values that are available.


Sorry Paul, but I think you are wrong. The 'adjustment' list should have descriptors for each channel that was set by the user. Those descriptors should have key for the channel as a referencetype, input b/w points as a list, output b/w points as a list, and gamma as a double. I would think that if those are not in the descriptor it's because the user didn't change the default values.

But if all you want to do is reapply the same settings later you don't really need to know what those setting were. You just store the descriptor that contains them for later use.

function newLevels() {

var desc2 = new ActionDescriptor();

var ref1 = new ActionReference();

ref1.putClass( charIDToTypeID('AdjL') );

desc2.putReference( charIDToTypeID('null'), ref1 );

var desc3 = new ActionDescriptor();

var desc4 = new ActionDescriptor();

desc4.putEnumerated( stringIDToTypeID('presetKind'), stringIDToTypeID('presetKindType'), stringIDToTypeID('presetKindDefault') );

desc3.putObject( charIDToTypeID('Type'), charIDToTypeID('Lvls'), desc4 );

desc2.putObject( charIDToTypeID('Usng'), charIDToTypeID('AdjL'), desc3 );

return executeAction( charIDToTypeID('Mk  '), desc2, DialogModes.ALL );

};

// store the descriptor holding the users values for later

var newLevelsDesc = newLevels();

// do something else like open another image

// then when needed make a new adjustment layer using those settings

executeAction( charIDToTypeID('Mk  '), newLevelsDesc, DialogModes.NO );

1 reply

Paul Riggott
Inspiring
March 13, 2013

I would think you need access to Photoshop CS3 to get all your details as  later versions do not record the details you want.

As an example here a couple of functions that may help...


var details = newLevels();
//example of creating a new level layer with extracted info
newLevelsWithInts(details[0],details[1]);

/*****************************
This function gets the following values
Adjust Shadow Input Level
Adjust Highlight Input Level
*****************************/
function newLevels() {
var desc2 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putClass( charIDToTypeID('AdjL') );
desc2.putReference( charIDToTypeID('null'), ref1 );
var desc3 = new ActionDescriptor();
var desc4 = new ActionDescriptor();
desc4.putEnumerated( stringIDToTypeID('presetKind'), stringIDToTypeID('presetKindType'), stringIDToTypeID('presetKindDefault') );
desc3.putObject( charIDToTypeID('Type'), charIDToTypeID('Lvls'), desc4 );
desc2.putObject( charIDToTypeID('Usng'), charIDToTypeID('AdjL'), desc3 );
var d = executeAction( charIDToTypeID('Mk  '), desc2, DialogModes.ALL );
d = d.getObjectValue(stringIDToTypeID('using')).getObjectValue(stringIDToTypeID('type')).getList (stringIDToTypeID('adjustment')).getObjectValue(0).getList (stringIDToTypeID('input'));
var levelsInput = new Array();
for(var a =0;a< d.count;a++){levelsInput.push( d.getInteger(a));}
return levelsInput;
};
/*****************************
This function put the following values
Adjust Shadow Input Level
Adjust Highlight Input Level
and creates a new levels layer
*****************************/
function newLevelsWithInts(int1,int2) {
var desc2 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putClass( charIDToTypeID('AdjL') );
desc2.putReference( charIDToTypeID('null'), ref1 );
var desc3 = new ActionDescriptor();
var desc4 = new ActionDescriptor();
var list1 = new ActionList();
var desc5 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Cmps') );
desc5.putReference( charIDToTypeID('Chnl'), ref2 );
var list2 = new ActionList();
list2.putInteger( Number(int1) );
list2.putInteger( Number(int2) );
desc5.putList( charIDToTypeID('Inpt'), list2 );
list1.putObject( charIDToTypeID('LvlA'), desc5 );
desc4.putList( charIDToTypeID('Adjs'), list1 );
desc3.putObject( charIDToTypeID('Type'), charIDToTypeID('Lvls'), desc4 );
desc2.putObject( charIDToTypeID('Usng'), charIDToTypeID('AdjL'), desc3 );
executeAction( charIDToTypeID('Mk  '), desc2, DialogModes.NO );
};

Inspiring
March 14, 2013

Ah thats annoying! Thanks for your help though, I could definately use this script to work with what I had planned. Is there a way to get it to set the midpoint too as it only seems to set the white and black point?

Thanks,

Mark

Paul Riggott
Inspiring
March 14, 2013

Sorry no, it seems that those are the only values that are available.