Utilize foreground/background colour in gradient fill
Hello everyone!
I am trying to make a gradient fill from a path or selection, the code (which I pulled from the scriptlistener), is filling gradient ONLY with the colour that was utilized when I recorded the action; I would like the gradient fill to utilize the foreground/background colours that are currently designated in PS whenever the script is ran. Anyone have any idea of how to do this? I'm still quite new to scripting (I'm primarily a painter), but I have been able (with LOTS of help) generate a few scripts that are useful to my workflow. I am using CS6; here is what I have thus far:
// Make Path from selection
var idMk = charIDToTypeID( "Mk " );
var desc405 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref221 = new ActionReference();
var idPath = charIDToTypeID( "Path" );
ref221.putClass( idPath );
desc405.putReference( idnull, ref221 );
var idFrom = charIDToTypeID( "From" );
var ref222 = new ActionReference();
var idcsel = charIDToTypeID( "csel" );
var idfsel = charIDToTypeID( "fsel" );
ref222.putProperty( idcsel, idfsel );
desc405.putReference( idFrom, ref222 );
var idTlrn = charIDToTypeID( "Tlrn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc405.putUnitDouble( idTlrn, idPxl, 1.000000 );
executeAction( idMk, desc405, DialogModes.NO );
// Make Gradient fill from Path
var idMk = charIDToTypeID( "Mk " );
var desc1188 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref965 = new ActionReference();
var idcontentLayer = stringIDToTypeID( "contentLayer" );
ref965.putClass( idcontentLayer );
desc1188.putReference( idnull, ref965 );
var idUsng = charIDToTypeID( "Usng" );
var desc1189 = new ActionDescriptor();
var idType = charIDToTypeID( "Type" );
var desc1190 = new ActionDescriptor();
var idType = charIDToTypeID( "Type" );
var idGrdT = charIDToTypeID( "GrdT" );
var idLnr = charIDToTypeID( "Lnr " );
desc1190.putEnumerated( idType, idGrdT, idLnr );
var idAlgn = charIDToTypeID( "Algn" );
desc1190.putBoolean( idAlgn, false );
var idGrad = charIDToTypeID( "Grad" );
var desc1191 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc1191.putString( idNm, """$$$/DefaultGradient/ForegroundToBackground=Foreground to Background""" );
var idGrdF = charIDToTypeID( "GrdF" );
var idGrdF = charIDToTypeID( "GrdF" );
var idCstS = charIDToTypeID( "CstS" );
desc1191.putEnumerated( idGrdF, idGrdF, idCstS );
var idIntr = charIDToTypeID( "Intr" );
desc1191.putDouble( idIntr, 4096.000000 );
var idClrs = charIDToTypeID( "Clrs" );
var list42 = new ActionList();
var desc1192 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var desc1193 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc1193.putDouble( idRd, 163.000005 );
var idGrn = charIDToTypeID( "Grn " );
desc1193.putDouble( idGrn, 39.003892 );
var idBl = charIDToTypeID( "Bl " );
desc1193.putDouble( idBl, 16.000001 );
var idRGBC = charIDToTypeID( "RGBC" );
desc1192.putObject( idClr, idRGBC, desc1193 );
var idType = charIDToTypeID( "Type" );
var idClry = charIDToTypeID( "Clry" );
var idUsrS = charIDToTypeID( "UsrS" );
desc1192.putEnumerated( idType, idClry, idUsrS );
var idLctn = charIDToTypeID( "Lctn" );
desc1192.putInteger( idLctn, 0 );
var idMdpn = charIDToTypeID( "Mdpn" );
desc1192.putInteger( idMdpn, 50 );
var idClrt = charIDToTypeID( "Clrt" );
list42.putObject( idClrt, desc1192 );
var desc1194 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var desc1195 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc1195.putDouble( idRd, 84.000003 );
var idGrn = charIDToTypeID( "Grn " );
desc1195.putDouble( idGrn, 103.000001 );
var idBl = charIDToTypeID( "Bl " );
desc1195.putDouble( idBl, 46.000001 );
var idRGBC = charIDToTypeID( "RGBC" );
desc1194.putObject( idClr, idRGBC, desc1195 );
var idType = charIDToTypeID( "Type" );
var idClry = charIDToTypeID( "Clry" );
var idUsrS = charIDToTypeID( "UsrS" );
desc1194.putEnumerated( idType, idClry, idUsrS );
var idLctn = charIDToTypeID( "Lctn" );
desc1194.putInteger( idLctn, 4096 );
var idMdpn = charIDToTypeID( "Mdpn" );
desc1194.putInteger( idMdpn, 50 );
var idClrt = charIDToTypeID( "Clrt" );
list42.putObject( idClrt, desc1194 );
desc1191.putList( idClrs, list42 );
var idTrns = charIDToTypeID( "Trns" );
var list43 = new ActionList();
var desc1196 = new ActionDescriptor();
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc1196.putUnitDouble( idOpct, idPrc, 100.000000 );
var idLctn = charIDToTypeID( "Lctn" );
desc1196.putInteger( idLctn, 0 );
var idMdpn = charIDToTypeID( "Mdpn" );
desc1196.putInteger( idMdpn, 50 );
var idTrnS = charIDToTypeID( "TrnS" );
list43.putObject( idTrnS, desc1196 );
var desc1197 = new ActionDescriptor();
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc1197.putUnitDouble( idOpct, idPrc, 100.000000 );
var idLctn = charIDToTypeID( "Lctn" );
desc1197.putInteger( idLctn, 4096 );
var idMdpn = charIDToTypeID( "Mdpn" );
desc1197.putInteger( idMdpn, 50 );
var idTrnS = charIDToTypeID( "TrnS" );
list43.putObject( idTrnS, desc1197 );
desc1191.putList( idTrns, list43 );
var idGrdn = charIDToTypeID( "Grdn" );
desc1190.putObject( idGrad, idGrdn, desc1191 );
var idgradientLayer = stringIDToTypeID( "gradientLayer" );
desc1189.putObject( idType, idgradientLayer, desc1190 );
var idcontentLayer = stringIDToTypeID( "contentLayer" );
desc1188.putObject( idUsng, idcontentLayer, desc1189 );
executeAction( idMk, desc1188, DialogModes.NO );
Any help is greatly appreciated!
Thanks,
-Eric
