Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you access layer style information in Photoshop?

I'm doing some research before I write a script for Photoshop CS3. I want to write the script in Photoshop with JavaScript.

I have looked through the Photoshop JavaScript Guide, but I can't find any way to get layer style information for a layer (stroke, gradient, outer glow, etc).

There is a way to set layer styles, but I haven't been able to find anything that lets you get the information.

I only have Photoshop CS3, so I'm looking for a solution that will suit that.

like image 753
Bryan Downing Avatar asked Sep 08 '11 18:09

Bryan Downing


2 Answers

Open the Adobe ExtendScript Toolkit. In the menu go to Help > Object-Model Viewer (or similar, mine is in german).

Inside the Object-Model browser in the "Browser" side-tab select Photoshop. Now you can search with the search field on the top right corner.

See the image below for ArtLayer's deifinition and ArtLayer.applyStyle():

http://i.stack.imgur.com/UEmj6.png

enter image description here

Search around, it's much better than adobe's documentation.

like image 68
thwd Avatar answered Sep 30 '22 16:09

thwd


I hope I am not too late, I reat your post, because I had the same problem and I found a solution on http://www.rags-int-inc.com/PhotoTechStuff/CollageTemplate/index.html. This guy has a script called "Layer Effects Options". You can download the source at the bottom.

Well it's only a panel to apply Effects, but if you browse through the code you can extract what you need.

Here is a little exsample (what I needed) for applying an stroke effect an the active layer

function newStrokeEffect(strokeSize, strokeColor, strokePosition) {
    var effectDescriptor = new ActionDescriptor();
    var effectColor = new ActionDescriptor();
    var strokeOpacity = 100.0;      // 0 - 100 %
    var strokeBlend = "Nrml";       // Normal[Nrml], ColorBurn[CBrn], SoftLight[SftL}, Color[Clr ]

    effectDescriptor.putBoolean(charIDToTypeID("enab"), true);
    effectDescriptor.putEnumerated(charIDToTypeID("Styl"), charIDToTypeID("FStl"), charIDToTypeID(strokePosition));
    effectDescriptor.putEnumerated(charIDToTypeID("PntT"), charIDToTypeID("FrFl"), charIDToTypeID("SClr"));
    effectDescriptor.putEnumerated(charIDToTypeID("Md  "), charIDToTypeID("BlnM"), charIDToTypeID(strokeBlend));
    effectDescriptor.putUnitDouble(charIDToTypeID("Opct"), charIDToTypeID("#Prc"), strokeOpacity);
    effectDescriptor.putUnitDouble(charIDToTypeID("Sz  "), charIDToTypeID("#Pxl"), strokeSize);
    effectColor.putDouble(charIDToTypeID("Rd  "), strokeColor.rgb.red);
    effectColor.putDouble(charIDToTypeID("Grn "), strokeColor.rgb.green);
    effectColor.putDouble(charIDToTypeID("Bl  "), strokeColor.rgb.blue);
    effectDescriptor.putObject(charIDToTypeID("Clr "), charIDToTypeID("RGBC"), effectColor);
    return(effectDescriptor);
}

var tmpC = new SolidColor();
tmpC.rgb.hexValue = "FF00FF";
var layerOptions = new ActionDescriptor();
var refr01 = new ActionReference();
var layerProperties = new ActionDescriptor();

layerOptions.putUnitDouble(charIDToTypeID("Scl "), charIDToTypeID("#Prc"), 400.0);

var layerEffects = newStrokeEffect(2, tmpC, "InsF");

layerOptions.putObject(charIDToTypeID("FrFX"), charIDToTypeID("FrFX"), layerEffects);

refr01.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("Lefx"));
refr01.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
layerProperties.putReference(charIDToTypeID("null"), refr01);
layerProperties.putObject(charIDToTypeID("T   "), charIDToTypeID("Lefx"), layerOptions);

try {
    executeAction(charIDToTypeID("setd"), layerProperties, DialogModes.NO);
} catch(ex) {
    if (ex != "Error: User cancelled the operation")
        alert(scriptName + " newLayerEffect() exception caught? line[" + ex.line + "] "  + ex);
}

I did not know the exact meaning of all lines (it is mainly copy & paste), but it works :-) (only tested it on Photoshop CS5)

like image 35
ahorn42 Avatar answered Sep 30 '22 16:09

ahorn42