使用Javascript在Illustrator中更改颜色 [英] Changing Colors in Illustrator with Javascript

查看:447
本文介绍了使用Javascript在Illustrator中更改颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是javascript的新手,我正在编写一个脚本来查找指定填充颜色的所有pathItems,并将它们更改为另一种填充颜色。这必须使用RGB或十六进制而不使用色板。到目前为止,我把一些其他脚本我发现,但我遇到了很多错误。这是我到目前为止:

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 without using swatches. So far I've put together bits of other scripts I found but I'm running into a lot of errors. Here is what I have so far:

var myDoc =app.activeDocument
var fillRGBColor = function (pathItem){
    var fillColor = new Array();
    fillColor[0] = myDoc.pathItem.fillColor.red;
    fillColor[1] = myDoc.pathItem.fillColor.green;
    fillColor[2] = myDoc.pathItem.fillColor.blue;
    return fillColor;
}

fillRGBColor();
var pathItems = myDoc.pathItems;
for (i=0; i<pathItems.length; i++){
    fillColor[255,255,255] ==fillColor[50,50,50];
}

谢谢!

推荐答案

我需要这个问题回答,但现有的答案是不完整的。这里是一个完整的工作解决方案。您指定从RGB和到RGB颜色,并调用fillRGBColor为您需要更改的颜色。

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.

下一步是找出如何为超过1个Illustrator文件自动化此脚本)

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);

这篇关于使用Javascript在Illustrator中更改颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆