What's new

Scripting Get values from an applied bevel and emboss effect for multiple layers?


Messages
7
Likes
0
I created this function below, to get some values from an applied bevel and emboss effect, like shading angle, shading altitude etc.
JavaScript:
alert("Angle: " + getBevelAndEmbossValues()[0] + "\nAltitude: " + getBevelAndEmbossValues()[1]); 

function getBevelAndEmbossValues() 
{   
    try 
    {   
        var ref = new ActionReference();   
        ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );     
        var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('bevelEmboss'));   
        return [desc.getUnitDoubleValue(stringIDToTypeID('localLightingAngle')), 
                desc.getUnitDoubleValue(stringIDToTypeID('localLightingAltitude'))]; 
    } 
    catch(e) 
    { 
        alert(e); 
    }   
};
What I want to do now, is to do the same thing but for multiple layers. Exactly like this function below does with layer's color. I tried several things but my knowledge level didn't help. Any idea?
JavaScript:
function getLayersData() 
{ 
    var lyrs = []; 
    var layers = 1; 
    while (true) 
    { 
        ref = new ActionReference(); 
        ref.putIndex(charIDToTypeID('Lyr '), layers); 

        try{var desc = executeActionGet(ref);}catch(err){alert(err);break;}; 

        var lyr = {}; 
        lyr.type = desc.getInteger(stringIDToTypeID("layerKind")); 
        lyr.name = desc.getString(charIDToTypeID("Nm  ")); 
        lyr.id = desc.getInteger(stringIDToTypeID("layerID")); 

        if (lyr.type == layerType && lyr.name.match(layerName)) 
        { 
            var adj = desc.getList(stringIDToTypeID("adjustment")).getObjectValue(0); 

            if (adj.hasKey(stringIDToTypeID("color")))   
            { 
                var curColor = new SolidColor(); 
                curColor.rgb.red = adj.getObjectValue(stringIDToTypeID("color")).getUnitDoubleValue(stringIDToTypeID("red")); 
                curColor.rgb.green = adj.getObjectValue(stringIDToTypeID("color")).getUnitDoubleValue(stringIDToTypeID("grain")); 
                curColor.rgb.blue = adj.getObjectValue(stringIDToTypeID("color")).getUnitDoubleValue(stringIDToTypeID("blue")); 
                lyr.color = curColor;   

                if (lyr.color.rgb.hexValue == currentColor[0]) 
                { 
                    lyrs.push(lyr);                                         
                };           
            }; 
        }; 
        layers++;             
    }; 
    return lyrs; 
};
 

thebestcpu

Guru
Messages
1,054
Likes
922
I have messed around and done a few scripts before yet not very productively (just don't use it often enough)
There are some forum members that are proficient so you might get an answer here yet want to let you know that Adobe has a dedicated scripting forum where I have been very successful getting response to my questions when I have them.
Hope this helps if you don't get an answer here
John Wheeler

https://forums.adobe.com/community/photoshop/photoshop_scripting
 
Messages
7
Likes
0
I have messed around and done a few scripts before yet not very productively (just don't use it often enough)
There are some forum members that are proficient so you might get an answer here yet want to let you know that Adobe has a dedicated scripting forum where I have been very successful getting response to my questions when I have them.
Hope this helps if you don't get an answer here
John Wheeler

https://forums.adobe.com/community/photoshop/photoshop_scripting
Hello my friend and thank you for your answer!!! I have already make the same question at adobe photoshop scripting forum, at graphicdesign and stackoverflow, but nothing... So, I am testing some things by my own and waiting if someone give an answer!!! :)
 

Paul MR

The Script Master
Messages
364
Likes
198
It is not that straight forward getting effects data, you need to check if you have the various keys are present before trying to get data.
Example of a layer with effects...
Code:
{
    "layerEffects": {
        "scale": 416.666666666667,
        "dropShadowMulti": [
            {
                "dropShadow": {
                    "enabled": false,
                    "present": false,
                    "showInDialog": true,
                    "mode": "multiply",
                    "color": {
                        "red": 0.03388419936527,
                        "grain": 0.15462099137949,
                        "blue": 0.09953482775018
                    },
                    "opacity": 35,
                    "useGlobalAngle": false,
                    "localLightingAngle": 120,
                    "distance": 26,
                    "chokeMatte": 0,
                    "blur": 7,
                    "noise": 0,
                    "antiAlias": false,
                    "transferSpec": {
                        "name": "Linear"
                    },
                    "layerConceals": true
                }
            }
        ],
        "innerShadowMulti": [
            {
                "innerShadow": {
                    "enabled": false,
                    "present": false,
                    "showInDialog": true,
                    "mode": "multiply",
                    "color": {
                        "red": 0.03388419936527,
                        "grain": 0.15462099137949,
                        "blue": 0.09953482775018
                    },
                    "opacity": 35,
                    "useGlobalAngle": true,
                    "localLightingAngle": 90,
                    "distance": 3,
                    "chokeMatte": 0,
                    "blur": 7,
                    "noise": 0,
                    "antiAlias": false,
                    "transferSpec": {
                        "name": "Linear"
                    }
                }
            }
        ],
        "outerGlow": {
            "enabled": true,
            "present": true,
            "showInDialog": true,
            "mode": "screen",
            "color": {
                "red": 255,
                "grain": 255,
                "blue": 255
            },
            "opacity": 35,
            "glowTechnique": "softMatte",
            "chokeMatte": 0,
            "blur": 7,
            "noise": 0,
            "shadingNoise": 0,
            "antiAlias": false,
            "transferSpec": {
                "name": "Linear"
            },
            "inputRange": 50
        },
        "solidFillMulti": [
            {
                "solidFill": {
                    "enabled": false,
                    "present": false,
                    "showInDialog": true,
                    "mode": "normal",
                    "color": {
                        "red": 129.314615428448,
                        "grain": 129.204922914505,
                        "blue": 129.258454442024
                    },
                    "opacity": 100
                }
            }
        ],
        "gradientFillMulti": [
            {
                "gradientFill": {
                    "enabled": false,
                    "present": false,
                    "showInDialog": true,
                    "mode": "hardLight",
                    "opacity": 100,
                    "gradient": {
                        "name": "$$$/DefaultGradient/ForegroundToBackground=Foreground to Background",
                        "gradientForm": "customStops",
                        "interfaceIconFrameDimmed": 4096,
                        "colors": [
                            {
                                "colorStop": {
                                    "color": {
                                        "red": 237.15618789196,
                                        "grain": 28.4194274246693,
                                        "blue": 36.2345744669437
                                    },
                                    "type": "userStop",
                                    "location": 0,
                                    "midpoint": 50
                                }
                            },
                            {
                                "colorStop": {
                                    "color": {
                                        "red": 60.9830796718597,
                                        "grain": 80.7802149653435,
                                        "blue": 162.85141825676
                                    },
                                    "type": "userStop",
                                    "location": 4096,
                                    "midpoint": 50
                                }
                            }
                        ],
                        "transparency": [
                            {
                                "transferSpec": {
                                    "opacity": 100,
                                    "location": 0,
                                    "midpoint": 50
                                }
                            },
                            {
                                "transferSpec": {
                                    "opacity": 100,
                                    "location": 4096,
                                    "midpoint": 50
                                }
                            }
                        ]
                    },
                    "angle": 90,
                    "type": "linear",
                    "reverse": true,
                    "dither": false,
                    "align": true,
                    "scale": 100,
                    "offset": {
                        "horizontal": 0,
                        "vertical": 0
                    }
                }
            }
        ],
        "frameFXMulti": [
            {
                "frameFX": {
                    "enabled": false,
                    "present": false,
                    "showInDialog": true,
                    "style": "insetFrame",
                    "paintType": "solidColor",
                    "mode": "normal",
                    "opacity": 100,
                    "size": 5,
                    "color": {
                        "red": 56.7176793515682,
                        "grain": 82.9238471388817,
                        "blue": 164.202671349049
                    },
                    "overprint": false
                }
            }
        ],
        "bevelEmboss": {
            "enabled": true,
            "present": true,
            "showInDialog": true,
            "highlightMode": "screen",
            "highlightColor": {
                "red": 255,
                "grain": 255,
                "blue": 255
            },
            "highlightOpacity": 50,
            "shadowMode": "multiply",
            "shadowColor": {
                "red": 0.03388419936527,
                "grain": 0.15462099137949,
                "blue": 0.09953482775018
            },
            "shadowOpacity": 50,
            "bevelTechnique": "preciseMatte",
            "bevelStyle": "innerBevel",
            "useGlobalAngle": true,
            "localLightingAngle": 90,
            "localLightingAltitude": 30,
            "strengthRatio": 100,
            "blur": 7,
            "bevelDirection": "stampOut",
            "transferSpec": {
                "name": "Linear"
            },
            "antialiasGloss": false,
            "softness": 0,
            "useShape": false,
            "useTexture": false
        }
    }
}
 
Messages
7
Likes
0
Well I finally managed to solve it!! Here is my solution... If anyone has anything better...
JavaScript:
var layers = getLayersData();
    alert (layers.length + ' layers found!!!' ,  'Message');
    
    function getLayersData()
    {
        var lyrs = [];
        var layers = 1;
        while (true)
        {
            ref = new ActionReference();
            ref.putIndex(charIDToTypeID('Lyr '), layers);
            
            try{var desc = executeActionGet(ref);}catch (err){break;};
            
            var lyr = {};
            lyr.type = desc.getInteger(stringIDToTypeID("layerKind"));
            lyr.name = desc.getString(charIDToTypeID("Nm  "));
            lyr.id = desc.getInteger(stringIDToTypeID("layerID"));
            
            if (lyr.type == '4')
            {                            
                ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
                if(desc.hasKey(stringIDToTypeID('layerEffects')))
                {
                    if(desc.getBoolean (stringIDToTypeID('layerFXVisible')))
                    {
                        desc = desc.getObjectValue(stringIDToTypeID('layerEffects'));
                        if(desc.hasKey(stringIDToTypeID('bevelEmboss')))
                        {
                            desc = desc.getObjectValue(stringIDToTypeID('bevelEmboss'));
                            if(desc.hasKey(stringIDToTypeID('localLightingAngle')))
                            {
                                var BevelAndEmbossAngle = desc.getUnitDoubleValue(stringIDToTypeID('localLightingAngle'));
                                if(BevelAndEmbossAngle == '90')
                                {
                                    lyrs.push(lyr);
                                }
                            }
                        }
                    }
                }
                
            };
            layers++;            
        };
        return lyrs;
    };
 

Top