更改Illustrator中选定对象颜色的脚本

时间:2019-09-28 22:18:17

标签: javascript adobe adobe-illustrator

我正在寻找脚本来将Illustrator中选定对象中的特定颜色更改为另一种颜色 我发现在“图层”中对所有颜色进行很少修改的代码如何将其设置为适用于所选项目。 谢谢

        var layer = app.activeDocument.activeLayer;
    var findColor = new RGBColor()
    findColor.red = 180;
    findColor.green = 90;
    findColor.blue = 90;

    var setColor = new RGBColor()
    setColor.red = 90;
    setColor.green = 180;
    setColor.blue = 180;

    for (var i = 0; i < layer.pathItems.length; i++) {
      var item = layer.pathItems[i];

      $.writeln("find colour ",Math.round( item.fillColor.red))
        if (Math.round(item.fillColor.red) == findColor.red &&
        Math.round(item.fillColor.green)== findColor.green &&
        Math.round(item.fillColor.blue) == findColor.blue)
       {
          $.writeln("Color function",i );
          item.fillColor = setColor;
       }
}

1 个答案:

答案 0 :(得分:0)

希望这会有所帮助,您可以尝试一下;

var docRef = app.activeDocument;

var setColor = new RGBColor();

 setColor.red = 90;
    setColor.green = 180;
    setColor.blue = 180;


theSelect = docRef.selection;
if(theSelect.length == 0){
    alert("No selected layer detected");}
    else{
        for (i=0;i<theSelect.length;i++){ 
        var SlctLyr= theSelect[i]
        SlctLyr.filled = true;
        SlctLyr.fillColor = setColor;}}