Illustrator Script not working

Community Beginner ,
Dec 15, 2020

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 ?

TOPICS
How to, Scripting, Third party plugins, Tools

Views

87

Likes

Translate

Translate

Report

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

Illustrator Script not working

Community Beginner ,
Dec 15, 2020

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 ?

TOPICS
How to, Scripting, Third party plugins, Tools

Views

88

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 15, 2020 0
Engaged ,
Dec 15, 2020

Copy link to clipboard

Copied

Which part doesn't work?  

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 15, 2020 0
Community Beginner ,
Dec 15, 2020

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 15, 2020 0
Adobe Community Professional ,
Dec 15, 2020

Copy link to clipboard

Copied

@O2-Creative may be able to fix up a powerscript that's just right for you.

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 15, 2020 1
Community Beginner ,
Dec 15, 2020

Copy link to clipboard

Copied

thanks, i'll contact him/her

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 15, 2020 0
Adobe Community Professional ,
Dec 15, 2020

Copy link to clipboard

Copied

It's him, Glenn Wilton - over in New Zealand, I think.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 15, 2020 1
Engaged ,
Dec 15, 2020

Copy link to clipboard

Copied

Edit:  Your script works for me. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 15, 2020 0
Most Valuable Participant ,
Dec 15, 2020

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 15, 2020 0
Resources