Copy link to clipboard
Copied
I'm very new to javascript and I am writing a script to find all pathItems of a specified fill color and change them to another fill color. This must be done in RGB or hex without using swatches. So far I've put together bits of other scripts I found but I'm running into a lot of errors. Here is what I have so far:
var myDoc =app.activeDocument
var fillRGBColor = function (pathItem){
var fillColor = new Array();
fillColor[0] = myDoc.pathItem.fillColor.red;
fillColor[1] = myDoc.pathItem.fillColor.green;
fillColor[2] = myDoc.pathItem.fillColor.blue;
return fillColor;
}
fillRGBColor();
var pathItems = myDoc.pathItems;
for (i=0; i<pathItems.length; i++){
fillColor[255,255,255] ==fillColor[50,50,50];
}
Thank you!
Copy link to clipboard
Copied
See this post from only the other day… Should contain 90% of what you want to do…
Copy link to clipboard
Copied
Thanks Muppet Mark! I modified the code based on that post:
var myDoc = app.activeDocument;
var oldFill = new RGBColor();
oldFill.red = 173;
oldFill.green = 173;
oldFill.blue = 132;
var newFill = new RGBColor();
newFill.red = 67;
newFill.green = 67;
newFill.blue = 181;
var paths = myDoc.pathItems;
for (var i=0; i<paths.length; i++){
if (paths.fillColor == oldFill){
paths.fillColor = newFill;
}
}
No errors anymore but nothing happens when I run the script.
Copy link to clipboard
Copied
You have to check values like below:
var myDoc = app.activeDocument;
var newFill = new RGBColor();
newFill.red = 67;
newFill.green = 67;
newFill.blue = 181;
var paths = myDoc.pathItems;
for (var i=0; i<paths.length; i++) {
var f = paths.fillColor;
if (f instanceof RGBColor // is it RGB
&& f.red.toFixed(0) == 173 //check red
&& f.green.toFixed(0) == 173 //check green
&& f.blue.toFixed(0) == 132 // check blue
) {
paths.fillColor = newFill;
}
}