Mobile app version of vmapp.org
Login or Join
Jessie844

: Script to change a color in all layers of a PSD file to another color? Is it possible to loop through all layers (there are too many layers) and replace one color with another. Need automated

@Jessie844

Posted in: #AdobePhotoshop #Javascript #PhotoshopScripting

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
}

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Jessie844

1 Comments

Sorted by latest first Latest Oldest Best

 

@Cody3331749

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme