find and replace text with color
HI, i'm writing an illustrator script to find replace some numbers to other number.
for example 511 to be changed to 410 like this.
for example 512 to be changed to 412 like this.
for example 513 to be changed to 413 like this.
......
for example 413 to be changed to 313 like this.
previous changed 413 should not affect...
here is my code.... plese help me to sortout....
replaceWord(/51/gim,"511")
replaceWord(/61/gim,"611")
replaceWord(/51/gim,"///")
var doc = app.activeDocument;
//replaceWord("INCORRECT", "CORRECT WORD");
var col = new RGBColor();
col.red = 255;
col.green = 0;
col.blue = 0;
var swatch = doc.swatches.add();
swatch.color = col;
swatch.name = "col";
function replaceWord(strFind, strReplace) {
var frame, words, word;
for (var i = 0; i < doc.textFrames.length; i++) {
frame = doc.textFrames[i].textRange;
words = frame.words;
for (var j = 0; j < words.length; j++) {
word = words[j];
//alert(word.contents);
alert(word.characterAttributes.fillColor.getByName);
if (word.fillColor != doc.swatches.getByName('col'))
{
new_string = word.contents.replace(strFind, strReplace)
if (new_string != word.contents) {
word.contents = new_string;
word.fillColor = swatch.color;
}
}
}
}
}
