0

Recently, I added a similar question about how to find all shapes with specific color and replace this color with an other one. Sergey Kritskiy gave me the solution with a working example which I changed slightly, according to my needs. The problem is, that if I try to change the color of a text layer, using the same script, it stops at var adj = desc.getList(stringIDToTypeID("adjustment")).getObjectValue(0); and I get this message The requested property does not exist.. So I need your help to find the right way to do the same thing for one or more text layers.

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 == 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        
};
  • 1
    it's maybe because not all properties are same for all kind of layer. in your situation i'll suggest to push out text layers by LayerKind.TEXT and than in that array use comparison of all text layers color by textItem.color :) hope it helps! – Mr.Online Jul 8 at 3:36
  • graphicdesign.stackexchange.com/questions/96819/… :D answer exist! – Mr.Online Jul 10 at 8:50

Your Answer

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

Browse other questions tagged or ask your own question.