This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//If you are making a plugin that needs to set or get and adjustment/gradient/color... layers, this hopefully saves you some time! | |
//This script makes easier some common Photoshop functions that are not directly available in the API and requires Low Level access and/or using the Script Listener. | |
//for debugging and exploring// | |
//writes a text file to the desktop with all the information of a selected layer, with this function, you can explore more types of what I have added, and look how the data is stored and used by the actions | |
//THIS WORKS WHEN YOU HAVE A SELECTED LAYER, AN ADJUSTMENT LAYER LIKE, Vibrance, Levels, Brightness, or a CONTENT LAYER like Gradients, Solid, etc | |
//uncomment/comment depending on what you want to explore. | |
function getInformation(){ | |
var info = ""; | |
var ref = new ActionReference(); | |
//ref.putEnumerated( app.stringIDToTypeID( 'contentLayer' ), app.charIDToTypeID( 'Ordn' ), app.charIDToTypeID( 'Trgt' ) );//gradient solid etc | |
ref.putEnumerated( app.charIDToTypeID( 'AdjL' ), app.charIDToTypeID( 'Ordn' ), app.charIDToTypeID( 'Trgt' ) );//adjustments | |
var desc = executeActionGet( ref ); | |
info = getRecursive(desc); | |
var f = new File( Folder.desktop + "/info.txt" ); | |
f.open( "w" ); | |
f.writeln( info ); | |
f.close(); | |
} | |
function getRecursive(obj){//obj is action descriptor or action list, not action reference | |
var info = ""; | |
for(var i = 0; i<obj.count; i++){ | |
var id = obj.typename=="ActionList"? i : obj.getKey(i); | |
var type = obj.getType(id); | |
info += "Index[" + i + "] - ID[" + id + "] - CharID[" + app.typeIDToCharID(id) + "] - StringID[" + app.typeIDToStringID(id) + "] - Type[" + type + "] .\n"; | |
switch(type){ | |
case DescValueType.ALIASTYPE: | |
//i never found an alias type | |
break; | |
case DescValueType.BOOLEANTYPE: | |
info += "Boolean: " + obj.getBoolean(id) + ".\n"; | |
break; | |
case DescValueType.CLASSTYPE: | |
info += "Class: " + obj.getClass(id) + ".\n"; | |
break; | |
case DescValueType.DOUBLETYPE: | |
info += "Double: " + obj.getDouble(id) + ".\n"; | |
break; | |
case DescValueType.ENUMERATEDTYPE: | |
var enumtypeid = obj.getEnumerationType(id); | |
var enumvalid = obj.getEnumerationValue(id); | |
info += "Enumeration Type: - ID[" + enumtypeid + "] - CharID[" + app.typeIDToCharID(enumtypeid) + "] - StringID[" + app.typeIDToStringID(enumtypeid) + "].\n"; | |
info += "Enumeration Value: - ID[" + enumvalid + "] - CharID[" + app.typeIDToCharID(enumvalid) + "] - StringID[" + app.typeIDToStringID(enumvalid) + "].\n"; | |
break; | |
case DescValueType.INTEGERTYPE: | |
info += "Integer: " + obj.getInteger(id) + ".\n"; | |
break; | |
case DescValueType.LARGEINTEGERTYPE: | |
info += "Large Integer: " + obj.getLargeInteger(id) + ".\n"; | |
break; | |
case DescValueType.LISTTYPE: | |
var objlist = obj.getList(id); | |
info += "List Count[" + objlist.count + "] - List Type Name[" + objlist.typename + "].\n"; | |
info += getRecursive(objlist); | |
break; | |
case DescValueType.OBJECTTYPE://ACTION DESCRIPTORS | |
var objtypeid = obj.getObjectType(id); | |
var objvalue = obj.getObjectValue(id); | |
info += "Object Type: - ID[" + objtypeid + "] - CharID[" + app.typeIDToCharID(objtypeid) + "] - StringID[" + app.typeIDToStringID(objtypeid) + "].\n"; | |
info += "Object Value: " + objvalue + " Object Count " + objvalue.count + ".\n"; | |
info += getRecursive(objvalue); | |
break; | |
case DescValueType.RAWTYPE: | |
var raw = obj.getData(id);//test | |
var rawinutf16 = ''; | |
for(var c = 0; c<raw.length; c++){ | |
rawinutf16 += ''+c+':['; | |
rawinutf16 += raw.charCodeAt(c); | |
rawinutf16 += ']\t'; | |
} | |
info += "Raw Data Plain: " + raw +"\n";//test | |
info += "UTF16CHAR: " + rawinutf16 +"\n"; | |
break; | |
case DescValueType.REFERENCETYPE: | |
info += "Reference: " + obj.getReference(id) + ".\n"; | |
break; | |
case DescValueType.STRINGTYPE: | |
info += "String: " + obj.getString(id) + ".\n"; | |
break; | |
case DescValueType.UNITDOUBLE: | |
var unitdoubletypeid = obj.getUnitDoubleType(id); | |
var unitdoublevalid = obj.getUnitDoubleValue(id); | |
info += "UnitDouble Type: - ID[" + unitdoubletypeid + "] - CharID[" + app.typeIDToCharID(unitdoubletypeid) + "] - StringID[" + app.typeIDToStringID(unitdoubletypeid) + "].\n"; | |
info += "UnitDouble Value: - ID[" + unitdoublevalid + "] - CharID[" + app.typeIDToCharID(unitdoublevalid) + "] - StringID[" + app.typeIDToStringID(unitdoublevalid) + "].\n"; | |
break; | |
} | |
info += "\n"; | |
} | |
return info; | |
} | |
//returns an integer; the index for some X information in the layers objects, for example in Gradients, some things like the alpha stops are not always in the same index, but because they also have code names like "Trns", this searches all the list, an then we have our number for using with getObjectValue(n) or other descriptor functions that asks for an index, and is not always the same | |
function GetIndexOfName(find, name){ | |
for(var i = 0; i<find.count; i++){ | |
var id = find.typename=="ActionList"? i : find.getKey(i); | |
if(app.typeIDToCharID(id) == name){ | |
return i; | |
} | |
} | |
} | |
//gets layer info in JSON format, | |
//it can then be passed around easily with the CLIENT (if you are making a CEP plugin) | |
//or use it right here in the HOST, | |
//also, it is usefull if your plugin will use some type of preset system | |
//here is were you can then add more types! | |
//for making a new type, like Solid Color Layer, you have to use getInformation() | |
//see how the action descriptor saves the layer values | |
//maybe you dont want JSON or an object, but the functions will show you where are each value stored, | |
function getLayerInfoJSON(layer, type){ | |
var info = ''; | |
SelectLayer(layer, "RGB ", false); | |
var ref = new ActionReference(); | |
switch(type){ | |
case "gradient": | |
ref.putEnumerated( app.stringIDToTypeID( 'contentLayer' ), app.charIDToTypeID( 'Ordn' ), app.charIDToTypeID( 'Trgt' ) ); | |
var desc = executeActionGet(ref); | |
info = GradientDescriptorToJSON(desc); | |
break; | |
case "levels": | |
ref.putEnumerated( app.charIDToTypeID( 'AdjL' ), app.charIDToTypeID( 'Ordn' ), app.charIDToTypeID( 'Trgt' ) ); | |
var desc = executeActionGet(ref); | |
info = LevelsDescriptorToJSON(desc); | |
break; | |
case "hsl": | |
ref.putEnumerated( app.charIDToTypeID( 'AdjL' ), app.charIDToTypeID( 'Ordn' ), app.charIDToTypeID( 'Trgt' ) ); | |
var desc = executeActionGet(ref); | |
info = HSLDescriptorToJSON(desc); | |
break; | |
case "vibrance": | |
ref.putEnumerated( app.charIDToTypeID( 'AdjL' ), app.charIDToTypeID( 'Ordn' ), app.charIDToTypeID( 'Trgt' ) ); | |
var desc = executeActionGet(ref); | |
info = VibranceDescriptorToJSON(desc); | |
break; | |
case "brightness": | |
ref.putEnumerated( app.charIDToTypeID( 'AdjL' ), app.charIDToTypeID( 'Ordn' ), app.charIDToTypeID( 'Trgt' ) ); | |
var desc = executeActionGet(ref); | |
info = BrightnessDescriptorToJSON(desc); | |
break; | |
} | |
return info; | |
} | |
//here are the individual action descriptors, | |
//all of this is figured out by reading the output text file of getInformation() | |
//then you have to "guess" what is each value... | |
function LevelsDescriptorToJSON(obj){ | |
var json = ''; | |
var list = obj.getList( obj.getKey(GetIndexOfName(obj, "Adjs")) );//adjustment is on key 30 or 28 | |
var desc0 = list.getObjectValue(0);//single item in index 0 | |
var raw = desc0.getData(desc0.getKey(0)); //raw data in key 0 of descriptor | |
//for RGB channel: | |
json += '"inputLeft" : ' + raw.charCodeAt(3) + ','; //input left is char 3 | |
json += '"inputRight" : ' + raw.charCodeAt(5) + ','; //input right is char 5 | |
json += '"outputLeft" : ' + raw.charCodeAt(7) + ','; //output left is char 7 | |
json += '"outputRight" : ' + raw.charCodeAt(9) + ','; //output right is char 9 | |
var gammabase = parseInt(raw.charCodeAt(10))*256; | |
var gammarest = parseInt(raw.charCodeAt(11)); | |
json += '"gamma" : ' + (gammabase+gammarest)/100 + ''; //gamma is ( char 10(*256) + char 11 ) /100 | |
return json; | |
} | |
function HSLDescriptorToJSON(obj){ | |
var json = ''; | |
var list = obj.getList( obj.getKey(GetIndexOfName(obj, "Adjs")) );//adjustment is on key 30 or 28 | |
var desc0 = list.getObjectValue(0);//single item in index 0 | |
var raw = desc0.getData(desc0.getKey(0)); //raw data in key 0 of descriptor | |
//for master: | |
//hue is code 11 - code 10 | |
var mhue = parseInt(raw.charCodeAt(11))-parseInt(raw.charCodeAt(10)); | |
//sat is code 13 - code 12 | |
var msat = parseInt(raw.charCodeAt(13))-parseInt(raw.charCodeAt(12)); | |
//lum is code 15 - code 14 | |
var mlum = parseInt(raw.charCodeAt(15))-parseInt(raw.charCodeAt(14)); | |
//colorize true 1 false 0 in code 2 | |
var colorize = raw.charCodeAt(2) == "1" ? true : false; | |
//hue | |
//if code 4 = 0, hue = code 5, | |
//if code 4 = 255, hue = (104) + code 5 | |
var chue; | |
if(raw.charCodeAt(4)=="0"){ | |
chue = raw.charCodeAt(5); | |
} else { | |
chue = parseInt(raw.charCodeAt(5))+104; | |
} | |
//sat is code 7-6 | |
var csat = parseInt(raw.charCodeAt(7))-parseInt(raw.charCodeAt(6)); | |
//lum is code 9-8 | |
var clum = parseInt(raw.charCodeAt(9))-parseInt(raw.charCodeAt(8)); | |
json += '"masterHue" : ' + mhue + ','; | |
json += '"masterSat" : ' + msat + ','; | |
json += '"masterLum" : ' + mlum + ','; | |
json += '"colorize" : ' + colorize + ','; | |
json += '"colorHue" : ' + chue + ','; | |
json += '"colorSat" : ' + csat + ','; | |
json += '"colorLum" : ' + clum + ''; | |
return json; | |
} | |
function GradientDescriptorToJSON(obj){ | |
var json = ''; | |
var list = obj.getList( obj.getKey(GetIndexOfName(obj, "Adjs")) );//gradient info "Adjs" is on key 30 or 28 from descriptor which is a list | |
var desc0 = list.getObjectValue(0); // which has 1 object (another descriptor) accesed by index not key, which has 3 or 4items | |
var angl = desc0.getUnitDoubleValue( desc0.getKey(0) ); //1st item is "Angl" in unitdouble | |
json += '"gradientAngle" : '+angl+','; | |
var type = app.typeIDToCharID(desc0.getEnumerationValue(desc0.getKey(1)));//2nd is gradient type,linear radial, etc | |
json += '"gradientType" : "'+type+'",'; | |
var scl; | |
if(app.typeIDToCharID(desc0.getKey(2))=="Scl "){ // 3d can be scale, if scale was never changed it is not listed ,so we write 100, as default, | |
scl = desc0.getUnitDoubleValue(desc0.getKey(2)); | |
} else { scl = 100; } | |
json += '"gradientScale" : '+scl+','; | |
var grad = desc0.getObjectValue(desc0.getKey(GetIndexOfName(desc0, "Grad"))); //3 or 4the gradient obj, 5 items, 1"name" 2"form" and 3"intersect" dont matter, 4 and 5 are colors and alpha stops | |
json += '"gradient" : {'; | |
json += '"colors" : {'; | |
var colors = grad.getList(grad.getKey(GetIndexOfName(grad, "Clrs")));// likely key 3, not always, so we use GetIndexOfName to find out | |
for(var i = 0; i<colors.count;i++){ | |
var color = colors.getObjectValue(i); | |
var rgb = color.getObjectValue(color.getKey(0)); | |
var r = rgb.getDouble(rgb.getKey(0)); | |
var g = rgb.getDouble(rgb.getKey(1)); | |
var b = rgb.getDouble(rgb.getKey(2)); | |
var loc = color.getInteger(color.getKey(2)); | |
var mid = color.getInteger(color.getKey(3)); | |
json += '"color'+i+'" : { "r" : '+r+', "g" : '+g+', "b" : '+b+', "loc" : '+loc+', "mid" : '+mid+' }'; | |
if(i==colors.count-1){ | |
json += ''; | |
} else { | |
json += ','; | |
} | |
} | |
json += '},'; //endofcolors | |
json += '"alphas" : {'; | |
var alphas = grad.getList(grad.getKey(GetIndexOfName(grad, "Trns")));// likely key 4 | |
for(var i = 0; i<alphas.count;i++){ | |
var alpha = alphas.getObjectValue(i); | |
var opc = alpha.getUnitDoubleValue(alpha.getKey(0)); | |
var loc = alpha.getInteger(alpha.getKey(1)); | |
var mid = alpha.getInteger(alpha.getKey(2)); | |
json += '"alpha'+i+'" : { "opacity" : '+opc+', "loc" : '+loc+', "mid" : '+mid+' }'; | |
if(i==alphas.count-1){ | |
json += ''; | |
} else { | |
json += ','; | |
} | |
} | |
json += '}';//endofalphas | |
//test | |
return json; | |
} | |
function BrightnessDescriptorToJSON(obj){ | |
var json = ''; | |
var list = obj.getList( obj.getKey(GetIndexOfName(obj, "Adjs")) ); | |
var desc0 = list.getObjectValue(0); | |
var raw = desc0.getData(desc0.getKey(0)); | |
var brightness; | |
var contrast; | |
if(raw.charCodeAt(0)=="0"){ | |
brightness = raw.charCodeAt(1); | |
} | |
else { | |
brightness = parseInt(raw.charCodeAt(1))-256; | |
} | |
if(raw.charCodeAt(2)=="0"){ | |
contrast = raw.charCodeAt(3); | |
} | |
else { | |
contrast = parseInt(raw.charCodeAt(3))-256; | |
} | |
json += '"brightness" : ' + brightness +','; | |
json += '"contrast" : ' + contrast + ''; | |
return json; | |
} | |
function VibranceDescriptorToJSON(obj){ | |
var json = ''; | |
var list = obj.getList( obj.getKey(GetIndexOfName(obj, "Adjs")) ); | |
var desc = list.getObjectValue(0); | |
var raw = desc.getData(desc.getKey(0)); | |
var vibrance; | |
var saturation; | |
var vIndex; | |
var sIndex; | |
if(raw.search(/vibrancelong/g)!=-1){ | |
vIndex = raw.search(/vibrancelong/g); | |
var vValue = raw.substr((vIndex+12),(vIndex+16)); | |
if(vValue.charCodeAt(0)=="0"){ | |
vibrance = vValue.charCodeAt(3); | |
} else { | |
vibrance = parseInt(vValue.charCodeAt(3))-256; | |
} | |
} else { | |
vIndex = null; | |
vibrance = 0; | |
} | |
if(raw.search(/Strtlong/g)!=-1){ | |
sIndex = raw.search(/Strtlong/g); | |
var sValue = raw.substr((sIndex+8),(sIndex+12)); | |
if(sValue.charCodeAt(0)=="0"){ | |
saturation = sValue.charCodeAt(3); | |
} else { | |
saturation = parseInt(sValue.charCodeAt(3))-256; | |
} | |
} else { | |
sIndex = null; | |
saturation = 0; | |
} | |
json += '"vibrance" : ' + vibrance + ','; | |
json += '"saturation" : ' + saturation + ''; | |
return json; | |
} | |
//next functions are learned from the ScriptListener plugin | |
//all parameters are type Number | |
function setLevels(InptL,InptR,Gamma,OtptL,OtptR){ | |
var idsetd = charIDToTypeID( "setd" ); | |
var desc = new ActionDescriptor(); | |
var idnull = charIDToTypeID( "null" ); | |
var ref = new ActionReference(); | |
var idAdjL = charIDToTypeID( "AdjL" ); | |
var idOrdn = charIDToTypeID( "Ordn" ); | |
var idTrgt = charIDToTypeID( "Trgt" ); | |
ref.putEnumerated( idAdjL, idOrdn, idTrgt ); | |
desc.putReference( idnull, ref ); | |
var idT = charIDToTypeID( "T " ); | |
var desc1 = new ActionDescriptor(); | |
var idAdjs = charIDToTypeID( "Adjs" ); | |
var list = new ActionList(); | |
var desc2 = new ActionDescriptor(); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var ref2 = new ActionReference(); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var idCmps = charIDToTypeID( "Cmps" ); | |
ref2.putEnumerated( idChnl, idChnl, idCmps ); | |
desc2.putReference( idChnl, ref2 ); | |
var idInpt = charIDToTypeID( "Inpt" ); | |
var list2 = new ActionList(); | |
list2.putInteger( InptL ); | |
list2.putInteger( InptR ); | |
desc2.putList( idInpt, list2 ); | |
var idGmm = charIDToTypeID( "Gmm " ); | |
desc2.putDouble( idGmm, Gamma ); | |
var idOtpt = charIDToTypeID( "Otpt" ); | |
var list3 = new ActionList(); | |
list3.putInteger( OtptL ); | |
list3.putInteger( OtptR ); | |
desc2.putList( idOtpt, list3 ); | |
var idLvlA = charIDToTypeID( "LvlA" ); | |
list.putObject( idLvlA, desc2 ); | |
desc1.putList( idAdjs, list ); | |
var idLvls = charIDToTypeID( "Lvls" ); | |
desc.putObject( idT, idLvls, desc1 ); | |
executeAction( idsetd, desc, DialogModes.NO ); | |
} | |
//layerName : String | |
//chanel : String ( "Msk ", "RGB " or "Blck" ) | |
//makeVisible : Boolean | |
function selectLayer(layerName, channel, makeVisible){ | |
var idslct = charIDToTypeID( "slct" ); | |
var desc = new ActionDescriptor(); | |
var idnull = charIDToTypeID( "null" ); | |
var ref = new ActionReference(); | |
var idLyr = charIDToTypeID( "Lyr " ); | |
ref.putName( idLyr, layerName ); //layerName String | |
desc.putReference( idnull, ref ); | |
var idMkVs = charIDToTypeID( "MkVs" ); | |
desc.putBoolean( idMkVs, false ); | |
//var idLyrI = charIDToTypeID( "LyrI" ); | |
// var list8 = new ActionList(); | |
// list8.putInteger( 278 ); | |
//desc13.putList( idLyrI, list8 ); | |
executeAction( idslct, desc, DialogModes.NO ); | |
var idslct = charIDToTypeID( "slct" ); | |
var desc1 = new ActionDescriptor(); | |
var idnull = charIDToTypeID( "null" ); | |
var ref2 = new ActionReference(); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var idMsk = charIDToTypeID( channel ); // "Msk ", "RGB " or "Blck" | |
ref2.putEnumerated( idChnl, idChnl, idMsk ); | |
desc1.putReference( idnull, ref2 ); | |
var idMkVs = charIDToTypeID( "MkVs" ); | |
desc1.putBoolean( idMkVs, makeVisible ); // bool | |
executeAction( idslct, desc1, DialogModes.NO ); | |
} | |
function setVibrance(vibrance,saturation){ | |
var idsetd = charIDToTypeID( "setd" ); | |
var desc = new ActionDescriptor(); | |
var idnull = charIDToTypeID( "null" ); | |
var ref = new ActionReference(); | |
var idAdjL = charIDToTypeID( "AdjL" ); | |
var idOrdn = charIDToTypeID( "Ordn" ); | |
var idTrgt = charIDToTypeID( "Trgt" ); | |
ref.putEnumerated( idAdjL, idOrdn, idTrgt ); | |
desc.putReference( idnull, ref ); | |
var idT = charIDToTypeID( "T " ); | |
var desc2 = new ActionDescriptor(); | |
var idvibrance = stringIDToTypeID( "vibrance" ); | |
desc2.putInteger( idvibrance, vibrance ); | |
var idStrt = charIDToTypeID( "Strt" ); | |
desc2.putInteger( idStrt, saturation ); | |
var idvibrance = stringIDToTypeID( "vibrance" ); | |
desc.putObject( idT, idvibrance, desc2 ); | |
executeAction( idsetd, desc, DialogModes.NO ); | |
} | |
//colorize : Boolean | |
//hue, sat, lum : Number | |
function setHSL(colorize,hue,saturation,luminosity){ | |
var idsetd = charIDToTypeID( "setd" ); | |
var desc = new ActionDescriptor(); | |
var idnull = charIDToTypeID( "null" ); | |
var ref = new ActionReference(); | |
var idAdjL = charIDToTypeID( "AdjL" ); | |
var idOrdn = charIDToTypeID( "Ordn" ); | |
var idTrgt = charIDToTypeID( "Trgt" ); | |
ref.putEnumerated( idAdjL, idOrdn, idTrgt ); | |
desc.putReference( idnull, ref ); | |
var idT = charIDToTypeID( "T " ); | |
var desc2 = new ActionDescriptor(); | |
var idpresetKind = stringIDToTypeID( "presetKind" ); | |
var idpresetKindType = stringIDToTypeID( "presetKindType" ); | |
var idpresetKindCustom = stringIDToTypeID( "presetKindCustom" ); | |
desc2.putEnumerated( idpresetKind, idpresetKindType, idpresetKindCustom ); | |
if(colorize){ | |
var idClrz = charIDToTypeID( "Clrz" ); | |
desc2.putBoolean( idClrz, true ); | |
} | |
var idAdjs = charIDToTypeID( "Adjs" ); | |
var list = new ActionList(); | |
var desc3 = new ActionDescriptor(); | |
var idH = charIDToTypeID( "H " ); | |
desc3.putInteger( idH, hue ); | |
var idStrt = charIDToTypeID( "Strt" ); | |
desc3.putInteger( idStrt, saturation ); | |
var idLght = charIDToTypeID( "Lght" ); | |
desc3.putInteger( idLght, luminosity ); | |
var idHsttwo = charIDToTypeID( "Hst2" ); | |
list.putObject( idHsttwo, desc3 ); | |
desc2.putList( idAdjs, list ); | |
var idHStr = charIDToTypeID( "HStr" ); | |
desc.putObject( idT, idHStr, desc2 ); | |
executeAction( idsetd, desc, DialogModes.NO ); | |
} | |
//g is an object, as returned by GradientDescriptorToJSON, looks like, for example, this: | |
/*"{ | |
"gradientAngle" : 90, | |
"gradientType" : "Lnr ", | |
"gradientScale" : 100, | |
"gradient" : { | |
"colors" : { | |
"color0" : { "r" : 59.9990844726563, "g" : 67.9989624023438, "b" : 69.9989318847656, "loc" : 0, "mid" : 50 }, | |
"color1" : { "r" : 106.396889984608, "g" : 109.661477208138, "b" : 119.000000506639, "loc" : 1073, "mid" : 50 }, | |
"color2" : { "r" : 125.093383938074, "g" : 140.031134784222, "b" : 147.000006437302, "loc" : 2311, "mid" : 50 }, | |
"color3" : { "r" : 88.3929924666882, "g" : 127.509727478027, "b" : 161.000005602837, "loc" : 3066, "mid" : 50 }, | |
"color4" : { "r" : 35.8560311794281, "g" : 54.5330739766359, "b" : 72.0000033080578, "loc" : 4096, "mid" : 50 } | |
}, | |
"alphas" : { | |
"alpha0" : { "opacity" : 100, "loc" : 0, "mid" : 50 }, | |
"alpha1" : { "opacity" : 100, "loc" : 4096, "mid" : 50 } | |
} | |
} | |
}*/ | |
function setGradient(g){ //GradientPreset | |
var idsetd = charIDToTypeID( "setd" ); | |
var desc = new ActionDescriptor(); | |
var idnull = charIDToTypeID( "null" ); | |
var ref = new ActionReference(); | |
var idcontentLayer = stringIDToTypeID( "contentLayer" ); | |
var idOrdn = charIDToTypeID( "Ordn" ); | |
var idTrgt = charIDToTypeID( "Trgt" ); | |
ref.putEnumerated( idcontentLayer, idOrdn, idTrgt ); | |
desc.putReference( idnull, ref ); | |
var idT = charIDToTypeID( "T " ); | |
var desc2 = new ActionDescriptor(); | |
var idAngl = charIDToTypeID( "Angl" ); | |
var idAng = charIDToTypeID( "#Ang" ); | |
desc2.putUnitDouble( idAngl, idAng, g.gradientAngle ); | |
var idType = charIDToTypeID( "Type" ); | |
var idGrdT = charIDToTypeID( "GrdT" ); | |
var idLnr = charIDToTypeID( g.gradientType ); | |
desc2.putEnumerated( idType, idGrdT, idLnr ); | |
var idScl = charIDToTypeID( "Scl " ); | |
var idPrc = charIDToTypeID( "#Prc" ); | |
desc2.putUnitDouble( idScl, idPrc, g.gradientScale ); | |
var idGrad = charIDToTypeID( "Grad" ); | |
var desc3 = new ActionDescriptor(); | |
var idNm = charIDToTypeID( "Nm " ); | |
desc3.putString( idNm, """Custom""" ); | |
var idGrdF = charIDToTypeID( "GrdF" ); | |
var idGrdF = charIDToTypeID( "GrdF" ); | |
var idCstS = charIDToTypeID( "CstS" ); | |
desc3.putEnumerated( idGrdF, idGrdF, idCstS ); | |
var idIntr = charIDToTypeID( "Intr" ); | |
desc3.putDouble( idIntr, 4096.000000 ); | |
var idClrs = charIDToTypeID( "Clrs" ); | |
var list6 = new ActionList(); | |
for(c in g.gradient.colors){ | |
var desc31 = new ActionDescriptor(); | |
var idClr = charIDToTypeID( "Clr " ); | |
var desc32 = new ActionDescriptor(); | |
var idRd = charIDToTypeID( "Rd " ); | |
desc32.putDouble( idRd, g.gradient.colors[c].r ); | |
var idGrn = charIDToTypeID( "Grn " ); | |
desc32.putDouble( idGrn, g.gradient.colors[c].g ); | |
var idBl = charIDToTypeID( "Bl " ); | |
desc32.putDouble( idBl, g.gradient.colors[c].b ); | |
var idRGBC = charIDToTypeID( "RGBC" ); | |
desc31.putObject( idClr, idRGBC, desc32 ); | |
var idType = charIDToTypeID( "Type" ); | |
var idClry = charIDToTypeID( "Clry" ); | |
var idUsrS = charIDToTypeID( "UsrS" ); | |
desc31.putEnumerated( idType, idClry, idUsrS ); | |
var idLctn = charIDToTypeID( "Lctn" ); | |
desc31.putInteger( idLctn, g.gradient.colors[c].loc ); | |
var idMdpn = charIDToTypeID( "Mdpn" ); | |
desc31.putInteger( idMdpn, g.gradient.colors[c].mid ); | |
var idClrt = charIDToTypeID( "Clrt" ); | |
list6.putObject( idClrt, desc31 ); | |
} | |
desc3.putList( idClrs, list6 ); | |
var idTrns = charIDToTypeID( "Trns" ); | |
var list7 = new ActionList(); | |
for(t in g.gradient.alphas){ | |
var desc35 = new ActionDescriptor(); | |
var idOpct = charIDToTypeID( "Opct" ); | |
var idPrc = charIDToTypeID( "#Prc" ); | |
desc35.putUnitDouble( idOpct, idPrc, g.gradient.alphas[t].opacity ); | |
var idLctn = charIDToTypeID( "Lctn" ); | |
desc35.putInteger( idLctn, g.gradient.alphas[t].loc ); | |
var idMdpn = charIDToTypeID( "Mdpn" ); | |
desc35.putInteger( idMdpn, g.gradient.alphas[t].mid ); | |
var idTrnS = charIDToTypeID( "TrnS" ); | |
list7.putObject( idTrnS, desc35 ); | |
} | |
desc3.putList( idTrns, list7 ); | |
var idGrdn = charIDToTypeID( "Grdn" ); | |
desc2.putObject( idGrad, idGrdn, desc30 ); | |
var idgradientLayer = stringIDToTypeID( "gradientLayer" ); | |
desc.putObject( idT, idgradientLayer, desc2 ); | |
executeAction( idsetd, desc, DialogModes.NO ); | |
} | |
//simple and usefull! | |
function autoLevels(){ | |
var idsetd = charIDToTypeID( "setd" ); | |
var desc = new ActionDescriptor(); | |
var idnull = charIDToTypeID( "null" ); | |
var ref = new ActionReference(); | |
var idAdjL = charIDToTypeID( "AdjL" ); | |
var idOrdn = charIDToTypeID( "Ordn" ); | |
var idTrgt = charIDToTypeID( "Trgt" ); | |
ref.putEnumerated( idAdjL, idOrdn, idTrgt ); | |
desc.putReference( idnull, ref ); | |
var idT = charIDToTypeID( "T " ); | |
var desc2 = new ActionDescriptor(); | |
var idAdjs = charIDToTypeID( "Adjs" ); | |
var list = new ActionList(); | |
var desc3 = new ActionDescriptor(); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var ref2 = new ActionReference(); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var idCmps = charIDToTypeID( "Cmps" ); | |
ref2.putEnumerated( idChnl, idChnl, idCmps ); | |
desc3.putReference( idChnl, ref2 ); | |
var idautoBlackWhite = stringIDToTypeID( "autoBlackWhite" ); | |
desc3.putBoolean( idautoBlackWhite, true ); | |
var idBlcC = charIDToTypeID( "BlcC" ); | |
desc3.putDouble( idBlcC, 0.000000 ); | |
var idWhtC = charIDToTypeID( "WhtC" ); | |
desc3.putDouble( idWhtC, 0.000000 ); | |
var idLvlA = charIDToTypeID( "LvlA" ); | |
list.putObject( idLvlA, desc3 ); | |
desc2.putList( idAdjs, list ); | |
var idLvls = charIDToTypeID( "Lvls" ); | |
desc.putObject( idT, idLvls, desc2 ); | |
executeAction( idsetd, desc, DialogModes.NO ); | |
} | |
//simple and usefull! | |
function resetLevelsDefault(){ | |
var idsetd = charIDToTypeID( "setd" ); | |
var desc = new ActionDescriptor(); | |
var idnull = charIDToTypeID( "null" ); | |
var ref = new ActionReference(); | |
var idAdjL = charIDToTypeID( "AdjL" ); | |
var idOrdn = charIDToTypeID( "Ordn" ); | |
var idTrgt = charIDToTypeID( "Trgt" ); | |
ref.putEnumerated( idAdjL, idOrdn, idTrgt ); | |
desc.putReference( idnull, ref ); | |
var idT = charIDToTypeID( "T " ); | |
var desc2 = new ActionDescriptor(); | |
var idpresetKind = stringIDToTypeID( "presetKind" ); | |
var idpresetKindType = stringIDToTypeID( "presetKindType" ); | |
var idpresetKindDefault = stringIDToTypeID( "presetKindDefault" ); | |
desc2.putEnumerated( idpresetKind, idpresetKindType, idpresetKindDefault ); | |
var idAdjs = charIDToTypeID( "Adjs" ); | |
var list = new ActionList(); | |
var desc3 = new ActionDescriptor(); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var ref2 = new ActionReference(); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var idRd = charIDToTypeID( "Rd " ); | |
ref2.putEnumerated( idChnl, idChnl, idRd ); | |
desc3.putReference( idChnl, ref2 ); | |
var idInpt = charIDToTypeID( "Inpt" ); | |
var list2 = new ActionList(); | |
list2.putInteger( 0 ); | |
list2.putInteger( 255 ); | |
desc3.putList( idInpt, list2 ); | |
var idLvlA = charIDToTypeID( "LvlA" ); | |
list.putObject( idLvlA, desc3 ); | |
var desc4 = new ActionDescriptor(); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var ref3 = new ActionReference(); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var idGrn = charIDToTypeID( "Grn " ); | |
ref3.putEnumerated( idChnl, idChnl, idGrn ); | |
desc4.putReference( idChnl, ref3 ); | |
var idInpt = charIDToTypeID( "Inpt" ); | |
var list3 = new ActionList(); | |
list3.putInteger( 0 ); | |
list3.putInteger( 255 ); | |
desc4.putList( idInpt, list3 ); | |
var idLvlA = charIDToTypeID( "LvlA" ); | |
list.putObject( idLvlA, desc4 ); | |
var desc5 = new ActionDescriptor(); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var ref4 = new ActionReference(); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var idBl = charIDToTypeID( "Bl " ); | |
ref4.putEnumerated( idChnl, idChnl, idBl ); | |
desc5.putReference( idChnl, ref4 ); | |
var idInpt = charIDToTypeID( "Inpt" ); | |
var list4 = new ActionList(); | |
list4.putInteger( 0 ); | |
list4.putInteger( 255 ); | |
desc5.putList( idInpt, list4 ); | |
var idLvlA = charIDToTypeID( "LvlA" ); | |
list.putObject( idLvlA, desc5 ); | |
desc2.putList( idAdjs, list ); | |
var idLvls = charIDToTypeID( "Lvls" ); | |
desc.putObject( idT, idLvls, desc2 ); | |
executeAction( idsetd, desc, DialogModes.NO ); | |
} | |
//layer must be previously selected, selectLayer("name", "Msk ", true) | |
//parameters are type Number (pixels) | |
function offsetGroupMask(x,y){ | |
var idOfst = charIDToTypeID( "Ofst" ); | |
var desc = new ActionDescriptor(); | |
var idHrzn = charIDToTypeID( "Hrzn" ); | |
desc.putInteger( idHrzn, x ); | |
var idVrtc = charIDToTypeID( "Vrtc" ); | |
desc.putInteger( idVrtc, y ); | |
var idFl = charIDToTypeID( "Fl " ); | |
var idFlMd = charIDToTypeID( "FlMd" ); | |
var idWrp = charIDToTypeID( "Wrp " ); | |
desc.putEnumerated( idFl, idFlMd, idWrp ); | |
executeAction( idOfst, desc, DialogModes.NO ); | |
} | |
No comments:
Post a Comment