1

I created this function below, to get some values from an applied bevel and emboss effect, like shading angle, shading altitude etc.

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?

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;  
};

UPDATE:

If I use scripting listener plugin to filter out the layers who contains bevel effect and then make a for loop, like Design Phoenix wrote in comments, I just get this...

layersFiltered();
function layersFiltered() {
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };    
    executeAction( s2t( "layersFiltered" ), undefined, DialogModes.NO );
}
  • 1
    i have very less knowledge when it comes to action descriptor because mostly when i need it i end up using scripting listener plugin. so in your case i would somehow manage to filter out the layers who contains bevel effect and then would've used for loop :) – Mr.Online Jul 8 at 6:31
  • @DesignPhoenix thank you for your answer my friend, but I don't know how this filtered out code can help me... I updated my question with what I get when I am filtering out this "action". Please take a look and tell me your opinion!!! Is this part of code what should I get or I am doing something wrong? Thank you for your time!!! – Simonetos The Greek Jul 8 at 6:50
  • 1
    well it seems photoshop action manager throwing out error while running function! i think i'm helpless here then since I'm also just newbie like you :D i have hopes from others ! – Mr.Online Jul 8 at 6:59
  • 1
    @DesignPhoenix thank you very much anyway my friend!!! :) I'll check if I am doing something wrong... – Simonetos The Greek Jul 8 at 7:04
1

Well I finally managed to solve it!! Here is my solution... If anyone has anything better...

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;
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.