script to get Photoshop Swatch Group or ACT file color values into javascript array
I’d like to get the color values from a Photoshop Swatch Group or from an ACT color table file into an array for processing in javascript.
Examples from this post can either add a new Swatch Group or get the names of the colors in Preset Swatch Groups.
And this script will import a new Swatch Group from an ACT file:
var idsetd = charIDToTypeID( "setd" );
var desc318 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref4 = new ActionReference();
var idPrpr = charIDToTypeID( "Prpr" );
var idClrs = charIDToTypeID( "Clrs" );
ref4.putProperty( idPrpr, idClrs );
var idcapp = charIDToTypeID( "capp" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref4.putEnumerated( idcapp, idOrdn, idTrgt );
desc318.putReference( idnull, ref4 );
var idT = charIDToTypeID( "T " );
desc318.putPath( idT, new File( "C:\\Users\\[userName]\\Pictures\\color tables\\test color table.act" ) );
var idAppe = charIDToTypeID( "Appe" );
desc318.putBoolean( idAppe, true );
executeAction( idsetd, desc318, DialogModes.NO );
This code lists Swatch Groups with their member Color Names, but the 'presetManager' appears to not include any of the imported Swatch Groups.
I’m also not sure how to get from the Color Name to color values that can be used in a Fill:
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);// get the app descriptor
var presetsList = desc.getList(stringIDToTypeID('presetManager'));// the presets list
var swatchDesc = presetsList.getObjectValue(1);// swatches is the second key
var nameList = swatchDesc.getList(charIDToTypeID("Nm "));// there is only one key in the swatch descriptor so get the list
var nameOfFirstSwatch = nameList.getString(0);// all the name list keys are strings data types so get the first swatch name
var nList = new Array();
for (var i=0;i<nameList.count;i++){
if (nameList.getString(i).slice(0,1)=="P") {
nList.push(nameList.getString(i)+"\n")
}
}
alert(nList)
And this script will create a new empty swatch group with name “My Test”:
var idmake = stringIDToTypeID( "make" );
var desc1530 = new ActionDescriptor();
var idnull = stringIDToTypeID( "null" );
var ref549 = new ActionReference();
var idswatchFolderClass = stringIDToTypeID( "swatchFolderClass" );
ref549.putClass( idswatchFolderClass );
desc1530.putReference( idnull, ref549 );
var idname = stringIDToTypeID( "name" );
desc1530.putString( idname, """myTest""" );
executeAction( idmake, desc1530, DialogModes.NO );
How can I get the color values from an imported member of the swatchFolderClass into a javascript array?
Or, can I get these color values directly from an ACT file into a javascript array?
Thanks!
