【问题标题】:Illustrator Javascript: Select Based on SwatchIllustrator Javascript:基于色板选择
【发布时间】:2017-09-10 02:52:03
【问题描述】:

是否可以制作一个 Javascript Illustrator 脚本来选择文档中具有特定颜色的所有内容?我在任何地方都找不到任何信息。我知道您可以使用“选择”下拉菜单执行我所要求的操作,但我需要将其作为脚本的一部分。

我尝试过类似的方法:

myDoc.selection = Spot.name("CutContour");

myDoc.selection = myDoc.spots.item("CutContour");

但都不起作用。

【问题讨论】:

    标签: javascript adobe-illustrator


    【解决方案1】:

    这应该对您有所帮助。对象的 fillColor 属性不是对样本对象的引用(因此我们可以检查其名称)。它是对颜色本身的描述(样本面板上没有附加字符串)。话虽如此,我们需要寻找颜色类型名称及其值以进行匹配。但是,如果您指定 CutContour 并且两种颜色具有此名称,则结果可能不是预期的。

    function getObjectsByColor ( colorName )
    {
    var doc, items, i = 0, n = 0, item, color, selectionArray = [];
    
    if ( app.documents.length == 0 ){ 
        alert("No documents open");
        return;
    }
    
    doc = app.activeDocument;
    try
    {
        color = doc.swatches.getByName ( colorName );
    }
    catch(e)
    {
        alert( "No such color !");
        return;
    }
    
    color = color.color ;
    
    items = doc.pageItems;
    n = items.length;
    if ( items.length == 0 )
    {
        alert( "No items found");
        return;
    }
    
    for ( i = 0; i < n ; i++ )
    {
        item = items[i];
        if ( item.fillColor.typename == color.typename
        && item.fillColor.cyan == color.cyan
        && item.fillColor.magenta == color.magenta
        && item.fillColor.yellow == color.yellow
        && item.fillColor.black == color.black )
        {
            selectionArray [ selectionArray.length ] = item;
        }
    }
    
    if ( selectionArray.length == 0 )
    {
        alert( "Nothing found" );
        return;
    }
    
    app.selection = selectionArray;
    }
    
    getObjectsByColor ("CutContour");
    

    洛伊克

    PS:您使用的是 Caldera RIP 吗?

    【讨论】:

      【解决方案2】:

      是的,有办法做到这一点。此脚本与 Illustrator 中的“选择相同的填充颜色”操作相同。注释代码以及您的帮助。它在 Illustrator CC 2017 中完美运行

      app.selection = null;
      if (app.activeDocument.length > 0) {
          try {
              var swatch = app.activeDocument.swatches.getByName('CMYK Red');
              var temp = app.documents[0].pathItems.rectangle(10, 10, 150, 150);
              temp.fillColor = swatch.color;
      
              // To select object that have CMYK Red swatch applied to stroke and fill.
              app.executeMenuCommand('Find Fill & Stroke menu item');
      
              // To select object that have CMYK Red swatch applied to fill.
              app.executeMenuCommand('Find Fill Color menu item');
      
              // To select object that have CMYK Red swatch applied to stroke.
              app.executeMenuCommand('Find Stroke Color menu item');
      
              temp.remove();
          } catch (e) {
              alert('CMYK Red swatch does not exists!!')
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多