Changing Colors in Illustrator with Javascript

后端 未结 2 1998

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 wi

相关标签:
2条回答
  • 2021-02-11 10:02

    Indeed you have a lot of erros in your script. Looking at the type of errors I suggest you to read Adobe Illustrator CS5 Reference: JavaScript or any JavaScript tutorial.

    In any case you can reduce your JavaScript errors by my modified version of your code.

    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);
    
    0 讨论(0)
  • 2021-02-11 10:18

    I needed this same question answered, but the existing answer was incomplete. Here is a full working solution. You specify the "from" RGB and the "to" RGB colors and call fillRGBColor for as many colors you need to change.

    The next step is to figure out how to automate this script for more than 1 illustrator file :)

    var fillRGBColor = function (pathItems, fr,fg,fb,tr,tg,tb){
        for (var i=0; i < pathItems.length; i++) {
    
            if (pathItems[i].fillColor.red == fr
               && pathItems[i].fillColor.green == fg
               && pathItems[i].fillColor.blue == fb) {
                    pathItems[i].fillColor.red = tr;
                    pathItems[i].fillColor.green = tg;
                    pathItems[i].fillColor.blue = tb;
            }
    
        }
    }
    
    fillRGBColor(app.activeDocument.pathItems, 20, 20, 20, 50, 50, 50);
    
    0 讨论(0)
提交回复
热议问题