Copy link to clipboard
Copied
We tried to create a script (js/jsx/vbs) to use in Adobe Illustrator, which lets us specify a RGB fill color and change it in 50+ Documents at once. We have already researched existing scripts for this purpose, but they do not work correctly.
This is our script, which is a combination of 2 existing scripts we found online:
var dir = Folder.selectDialog("Where are your Illustrator Documents?");var files = dir.getFiles("*.ai"); for(var f = 0; f < files.length; f++){ var doc = app.open(files[f]);
var fillRGBColor = function (pathItems, r, g, b){
for (var i=0; i < pathItems.length; i++) {
pathItems[i].fillColor.red = r;
pathItems[i].fillColor.green = g;
pathItems[i].fillColor.blue = b;
}
}
fillRGBColor(app.activeDocument.pathItems, 50, 50, 50);
doc.close(SaveOptions.SAVECHANGES);}
We also found a Powerscript, which does exactly what we want, but it does not support batch processing and every file needs to be opened manually.
https://o2creative.co.nz/shop/Color_Replacer_PowerScript_for_Adobe_Illustrator
does anyone know how to fix this script or is there a way to make the powerscript work on multiple files ?
Yes. The script should work.
For pathItems!
try this part of your script with an opened document with a few PATHITEMS
var fillRGBColor = function (pathItems, r, g, b){
for (var i=0; i < pathItems.length; i++) {
pathItems[i].fillColor.red = r;
pathItems[i].fillColor.green = g;
pathItems[i].fillColor.blue = b;
}
}
//fillRGBColor(app.activeDocument.pathItems, 50, 50, 50); // dark grey
fillRGBColor(app.activeDocument.pathItems, 255, 255, 0); // yellow
Copy link to clipboard
Copied
Which part doesn't work?
Copy link to clipboard
Copied
the middle part (changing color). when i enter values for the source and new fill color, it seems to change other colours (i think mainly blacks and whites) as well... and it seems to change everything INTO the source color instead of the new one.
i dont know much about illustrator scripts so i may just be using it wrong... any help is appreciated
Copy link to clipboard
Copied
@O2-Creative may be able to fix up a powerscript that's just right for you.
Copy link to clipboard
Copied
thanks, i'll contact him/her
Copy link to clipboard
Copied
It's him, Glenn Wilton - over in New Zealand, I think.
Copy link to clipboard
Copied
Edit: Your script works for me.
Copy link to clipboard
Copied
Yes. The script should work.
For pathItems!
try this part of your script with an opened document with a few PATHITEMS
var fillRGBColor = function (pathItems, r, g, b){
for (var i=0; i < pathItems.length; i++) {
pathItems[i].fillColor.red = r;
pathItems[i].fillColor.green = g;
pathItems[i].fillColor.blue = b;
}
}
//fillRGBColor(app.activeDocument.pathItems, 50, 50, 50); // dark grey
fillRGBColor(app.activeDocument.pathItems, 255, 255, 0); // yellow