Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Find and replace Fill Color In Script for batch processing

New Here ,
Jan 13, 2020 Jan 13, 2020

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();

colro-change.GIFexpand image

TOPICS
Scripting
932
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
LEGEND ,
Jan 13, 2020 Jan 13, 2020

I ha e never used this API but I observe that you never initialised oldTopColor. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2021 Aug 31, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 31, 2021 Aug 31, 2021
LATEST

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines