Reputation: 20107
I have a Photoshop Javascript script that cycles through different layers and I want to give a different outer glow to each layer based on the name of the layer.
Can someone give an example on how to change the blending options of an ArtLayer class programatically?
Upvotes: 1
Views: 2835
Reputation: 59
Unfortunately, there's no easy way to add layer styles.
There is .applyStyle("Puzzle (Image)")
but other styles are not included in documentation, and I couldn't find other styles anywhere.
So you have to use workaround (tricky and complicated process).
First of all, you'll need to make action (add outer glow to layer) and then convert to .jsx script.
You need to use this script for conversion: http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/apps/ActionToJavascript.jsx?revision=1.29
Run it from Ps or from ExtendScript, choose your action and save it.
In your newly created script, you'll see horrible and unreadable code, it will work right away, however you'll need to make function if you want to use different settings (color, opacity, blend mode, etc).
Here's clean version.
cTID = function(s){ return app.charIDToTypeID(s); };
sTID = function(s){ return app.stringIDToTypeID(s); };
// Add Style: Glow
function addStyleGlow( R, G, B, blendingMode, opacity, spread, size ){
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Prpr'), cTID('Lefx'));
ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
var desc2 = new ActionDescriptor();
desc2.putUnitDouble(cTID('Scl '), cTID('#Prc'), 100);
// Glow color
var desc4 = new ActionDescriptor();
var rgb = new Array();
desc4.putDouble(cTID('Rd '), R);
desc4.putDouble(cTID('Grn '), G);
desc4.putDouble(cTID('Bl '), B);
// Blending mode of the effect
var desc3 = new ActionDescriptor();
desc3.putBoolean(cTID('enab'), true);
desc3.putEnumerated( cTID('Md '), cTID('BlnM'), cTID(blendingMode) );
desc3.putObject(cTID('Clr '), sTID("RGBColor"), desc4);
// Opacity
desc3.putUnitDouble(cTID('Opct'), cTID('#Prc'), opacity);
desc3.putEnumerated(cTID('GlwT'), cTID('BETE'), cTID('SfBL'));
// Spread
desc3.putUnitDouble(cTID('Ckmt'), cTID('#Pxl'), spread);
// Size
desc3.putUnitDouble(cTID('blur'), cTID('#Pxl'), size);
// Noise
desc3.putUnitDouble(cTID('Nose'), cTID('#Prc'), 0);
// Quality: Jitter
desc3.putUnitDouble(cTID('ShdN'), cTID('#Prc'), 0);
desc3.putBoolean(cTID('AntA'), true);
var desc5 = new ActionDescriptor();
desc5.putString(cTID('Nm '), "Linear");
desc3.putObject(cTID('TrnS'), cTID('ShpC'), desc5);
// Quality: Range
desc3.putUnitDouble(cTID('Inpr'), cTID('#Prc'), 50);
desc2.putObject(cTID('OrGl'), cTID('OrGl'), desc3);
desc1.putObject(cTID('T '), cTID('Lefx'), desc2);
executeAction(cTID('setd'), desc1, DialogModes.NO);
}; // End of Add Style: Glow
You will need another script file to call that function, place it in same folder (replace "antoxa_myGlow.jsx" with your script name)
//@include "antoxa_myGlow.jsx"
// R, G, B, blend mode, opacity, spread, size
addStyleGlow(255, 255, 54, 'Nrml', 75, 0, 5);
Currently it will work only with one selected layer, if you choose multiple layers, it will give you error. I don't know how to apply function to multiple selected layers yet.
Upvotes: 2