Is it possible to loop through all layers (there are too many layers) and replace one color with another. Need automated approach, script or simple action.
Loop through all layers{
Change Fill color A to X
Change Text color A to X
}
Graphic Design Stack Exchange is a question and answer site for Graphic Design professionals, students, and enthusiasts. It only takes a minute to sign up.
Sign up to join this communityIs it possible to loop through all layers (there are too many layers) and replace one color with another. Need automated approach, script or simple action.
Loop through all layers{
Change Fill color A to X
Change Text color A to X
}
Changing text colour A to X is straight forward (provided you have no groups than it get a bit more complex):
var colourA = "28bd98";
var colourY = "ff00ff";
changeFontColour(colourA, colourY);
function changeFontColour(X,Y)
{
var numOfLayers = app.activeDocument.layers.length;
// main loop
for (var i = numOfLayers -1; i >= 0 ; i--)
{
var thisLayer = app.activeDocument.layers[i];
if (app.activeDocument.layers[i].kind == 'LayerKind.TEXT')
{
var currentFontCol = getFontColour(thisLayer);
// alert(currentFontCol + "\n" + X);
if (currentFontCol.toUpperCase() == X.toUpperCase())
{
var myColour = new SolidColor();
var RGB = HEXtoRGB(Y);
myColour.rgb.red = RGB[0];
myColour.rgb.green = RGB[1];
myColour.rgb.blue = RGB[2];
// replace text colour
thisLayer.textItem.color = myColour;
}
}
} //end of loop
}
function getFontColour(alayer)
{
var fontColor = alayer.textItem.color;
return fontColor.rgb.hexValue;
}
function HEXtoRGB (hex)
{
var c = 1
if (hex.charAt(0) != "#") c = 0;
var r = parseInt(hex.substring(c,c+2),16)
var g = parseInt(hex.substring(c+2,c+4),16)
var b = parseInt(hex.substring(c+4,c+6),16)
return [r, g, b];
}
Image > Adjustment > Replace color
to change a color, I need automation of this process if we have too many layers.