Quantcast
Channel: Adobe Community: Message List - Photoshop Scripting
Viewing all articles
Browse latest Browse all 27456

Re: Get layer style parameters?

$
0
0

In case you're still interested about getting and setting layer styles parameters, I've just released a new module jamStyles of my open-source JSON Action Manager scripting library, which provides full support for blending options and layer effects using a fully-documented, simplified JSON object format.

 

I've also written a quick tutorial showing how to perform a few standard operations, using mainly the two functions jamStyles.getLayerStyle and jamStyles.setLayerStyle.

 

For instance, the following code sample will set a mildly complex layer style:

 

var layerStyleObj ={    "blendOptions":    {        "fillOpacity": 70,        "blendInterior": true    },    "layerEffects":    {        "scale": 100,        "dropShadow":        {            "enabled": true,            "mode": "multiply",            "color":            {                "red": 0,                "green": 0,                "blue": 0            },            "opacity": 70,            "useGlobalAngle": false,            "localLightingAngle": 90,            "distance": 6,            "chokeMatte": 0,            "blur": 4,            "noise": 0,            "antiAlias": false,            "transparencyShape":            {                "name": "Linear",                "curve":                [                    {                        "horizontal": 0,                        "vertical": 0                    },                    {                        "horizontal": 255,                        "vertical": 255                    }                ]            },            "layerConceals": true        },        "innerShadow":        {            "enabled": true,            "mode": "multiply",            "color":            {                "red": 0,                "green": 0,                "blue": 0            },            "opacity": 70,            "useGlobalAngle": false,            "localLightingAngle": 90,            "distance": 10,            "chokeMatte": 15,            "blur": 20,            "noise": 0,            "antiAlias": false,            "transparencyShape":            {                "name": "Linear",                "curve":                [                    {                        "horizontal": 0,                        "vertical": 0                    },                    {                        "horizontal": 255,                        "vertical": 255                    }                ]            }        },        "innerGlow":        {            "enabled": true,            "mode": "linearDodge",            "color":            {                "red": 255,                "green": 246,                "blue": 168            },            "opacity": 31,            "glowTechnique": "preciseMatte",            "chokeMatte": 0,            "blur": 20,            "shadingNoise": 0,            "noise": 0,            "antiAlias": true,            "innerGlowSource": "centerGlow",            "transparencyShape":            {                "name": "Half Round",                "curve":                [                    {                        "horizontal": 0,                        "vertical": 0                    },                    {                        "horizontal": 29,                        "vertical": 71                    },                    {                        "horizontal": 87,                        "vertical": 167                    },                    {                        "horizontal": 195,                        "vertical": 240                    },                    {                        "horizontal": 255,                        "vertical": 255                    }                ]            },            "inputRange": 43        },        "bevelEmboss":        {            "enabled": true,            "highlightMode": "screen",            "highlightColor":            {                "red": 255,                "green": 255,                "blue": 255            },            "highlightOpacity": 100,            "shadowMode": "multiply",            "shadowColor":            {                "red": 0,                "green": 0,                "blue": 0            },            "shadowOpacity": 100,            "bevelTechnique": "softMatte",            "bevelStyle": "innerBevel",            "useGlobalAngle": false,            "localLightingAngle": 90,            "localLightingAltitude": 75,            "strengthRatio": 80,            "blur": 16,            "bevelDirection": "stampIn",            "transparencyShape":            {                "name": "Linear",                "curve":                [                    {                        "horizontal": 0,                        "vertical": 0                    },                    {                        "horizontal": 255,                        "vertical": 255                    }                ]            },            "antialiasGloss": false,            "softness": 0,            "useShape": true,            "mappingShape":            {                "name": "Half Round",                "curve":                [                    {                        "horizontal": 0,                        "vertical": 0                    },                    {                        "horizontal": 29,                        "vertical": 71                    },                    {                        "horizontal": 87,                        "vertical": 167                    },                    {                        "horizontal": 195,                        "vertical": 240                    },                    {                        "horizontal": 255,                        "vertical": 255                    }                ]            },            "antiAlias": true,            "inputRange": 70,            "useTexture": false        },        "solidFill":        {            "enabled": true,            "mode": "normal",            "opacity": 100,            "color":            {                "red": 0,                "green": 102,                "blue": 255            }        }    }};
jamStyles.setLayerStyle (layerStyleObj);

 

And this code will let you read out the drop shadow distance:

 

var layerStyleObj = jamStyles.getLayerStyle ();if (layerStyleObj){    if ("layerEffects" in layerStyleObj)    {        var layerEffectsObj = layerStyleObj["layerEffects"];        if ("dropShadow" in layerEffectsObj)        {            var dropShadowObj = layerEffectsObj["dropShadow"];            alert ("Drop shadow distance: " + dropShadowObj["distance"]);        }    }}

 

Actually, if you know for sure that the current layer you're working on has layer effects, including a drop shadow effect, the code can be as short as:

 

var layerStyleObj = jamStyles.getLayerStyle ();
alert ("Drop shadow distance: " + layerStyleObj["layerEffects"]["dropShadow"]["distance"]);

 

Or, even shorter, using dot notation:

 

alert ("Drop shadow distance: " + jamStyles.getLayerStyle ().layerEffects.dropShadow.distance);

 

HTH,

 

     --Mikaeru


Viewing all articles
Browse latest Browse all 27456

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>