Find and replace Fill Color In Script for batch processing
Copy link to clipboard
Copied
I want to replace the speciefic color on the page Like my RGB Value is 0 0 255 i want to replace that with 48 169 39 my script change all the color on the artboard. how do i fix this please help my code
function ConvertColors() {
/* REPLACE THESE RGB VALUES */
var topColor = new RGBColor();
topColor.red = 0; // <- HERE
topColor.green = 0; // <- HERE
topColor.blue = 255; // <-HERE
var bottomColor = new RGBColor();
bottomColor.red = 48; // <- HERE
bottomColor.green = 169; // <- HERE
bottomColor.blue = 39; // <- HERE
/* ~~~~~~~~~~~~~~~~~~~ */
var dir = Folder.selectDialog("Where?");
var files = dir.getFiles("*.eps");
// loop through all the files in the selected directory
for(var f = 0; f < files.length; f++){
var doc = app.open(files[f]);
// loop through all paths and change the colors based on current fill
var paths = doc.pathItems;
for( var i = 0, ii = paths.length; i < ii; i++ ) {
var curPath = paths[i];
// check the fill color to see if it has the same Red value as the old top color
if( curPath.fillColor.red == oldTopColor ) {
curPath.fillColor = topColor;
}
// if not it must be the bottom color
else {
curPath.fillColor = bottomColor;
}
}
// close and save the changes
doc.close(SaveOptions.SAVECHANGES);
}
}
ConvertColors();
Explore related tutorials & articles
Copy link to clipboard
Copied
I ha e never used this API but I observe that you never initialised oldTopColor.
Copy link to clipboard
Copied
Have you found a solution for this issue?
I have exactly the same task and I don't know, how to configure the script to work as expected...
Best wishes, Thomas
Copy link to clipboard
Copied
You cannot just do == oldTopColor, it's got to be like
curPath.fillColor.red == oldTopColor.red &&
curPath.fillColor.green == oldTopColor.green &&
curPath.fillColor.blue == oldTopColor.blue
And sometimes that won't even work if there are some rounding issues with any decimal places, so you may want to do Math.round() to each of those items.
Math.round(curPath.fillColor.red) == Math.round(oldTopColor.red) &&
Math.round(curPath.fillColor.green) == Math.round(oldTopColor.green) &&
Math.round(curPath.fillColor.blue) == Math.round(oldTopColor.blue)

