Batch replace color with another color
Hi,
I would desperately need some assistance in trying to accomplish batch editing of ai-files via JavaScript.
What I would need to do, is go through a number (many!) of files, find items with certain swatch color (referenced by its name), and replace the item-fill with another swatch-color (also referenced by its name). Then save the document with another name.
Other parts I have managed to do, except find/compare/modify the fill color of an item.
I have gone through these forums and tried a number of things to a point where I am currently very confused and frustrated ![]()
Some details (if it helps any), I'm using Illustrator CS3 and JavaScript.
Here's the closest where I got with trying to find a certain color and eventually changing it:
#target illustrator
var sourceFile, findColor, replaceColor;
sourceFile = new File().openDlg('Please select your Illustrator file…');
open(sourceFile);
var docRef = app.activeDocument;findColor = docRef.swatches.getByName("vih");
// replaceColor not yet used anywhere
replaceColor = docRef.swatches.getByName("sin");for(var obj = docRef.pageItems.length - 1; obj >= 0; obj--) {
if(docRef.pageItems[obj].fillColor == findColor) {
alert("Match found"); //It never seems to get here, so my comparison clearly is not working?
}
else {
alert ("No specified color found!");
}
}docRef.close();
(and yes, I'm completely new with java-scripting, so even this is constructed from bits of sample-scripts and other scripts found from these forums)
Please, I would really appreciate any help, this can't really be such a difficult task to do... can it?
BR,
Johanna