2013-10-18 33 views
3

我遇到了Illustrator CS6的腳本問題 - 一直困擾着我很長一段時間。組合路徑內的組。Illustrator將複合路徑中的對象分組

我已經設置了一個腳本來提取Illustrator文件中所有使用的顏色以及半色調信息,CMYK等。它基本上遍歷文件中的每個路徑並查看其填充顏色(如果有的話),筆畫顏色(如果有的話),漸變停止(如果有的話)等。如果它正在查看的項目是一個組,它就會跳入該組並通過遞歸調用來查看其所有組件相同的功能。相同的複合路徑。它也被設置爲處理大多數光柵圖像,如果其彩色位圖或CMYK圖像等報告回來。

但是,腳本失敗時,它會運行到包含組的組合路徑中。現在,通常情況下,這在Illustrator中是不可能的。如果您嘗試創建一組兩條路徑,然後複合它們,Illustrator只會刪除該組。但是,有些人使用某些程序,當從其中導出EPS文件時,某些路徑最終會成爲複合路徑中的組。除了訓練我所有的人在這裏尋找這些問題的途徑之外,我還有什麼可以用腳本來做的嗎?這裏是劇本我目前有:

/** 
* The main part of the script that will run in Illustrator, getting the text of the object we're looking for. 
* 
* @param {File} theFile The file object that will be opened in Illustrator and checked. 
*/ 
function findInfo(theFile) 
{ 
    var document = app.open(theFile); 
    var prodInfo = new Array; 

    // This first section of the Illustrator script will just get the template name of the current product. 
    var templateName = new String; 

    var templateLayer = document.layers[2]; 
    $.writeln(templateLayer.name); 
    for (var i = templateLayer.pageItems.length - 1; i >= 0; i--) 
    { 
     var pName = templateLayer.pageItems[i].name; 
     if (pName != "") 
     { 
      templateName = templateLayer.pageItems[i].name; 
     } 
    } 

    $.writeln("templateName (inside Illustrator Script) is " + templateName); 

    // This second section of the Illustrator script will gather all of the used colors and store them in an array. 
    var colorsArray = []; 
    var bHalftones = false; 
    var bFourCP = false; 
    var bReg = false; 
    colorsInUse(document.layers[0]); 

    function colorsInUse(currPageItem) { 
     for (var i = 0; i < currPageItem.pageItems.length; i++) { 
      // Stepping through each item on the layer. 
      var currentItem = currPageItem.pageItems[i]; 
      // $.writeln("current item is " + currentItem.typename); 
      // $.writeln("Does it have a fill color? " + currentItem.fillColor); 
      if (currentItem.typename === "GroupItem" && !currentItem.guides) { 
       // If it's a group, dig into the group and start the function over. 
       colorsInUse(currentItem); 
      } else if (currentItem.typename == "TextFrame") { 
       var charAttrib = currentItem.textRange.characterAttributes; 
       getColors(charAttrib, colorsArray); 
      } else if (currentItem.typename === "RasterItem") { 
       if (currentItem.imageColorSpace === ImageColorSpace.CMYK) { 
        $.writeln("Four-color process image in artwork."); 
       } else if (currentItem.channels > 1 || currentItem.imageColorSpace === ImageColorSpace.GrayScale) { 
        if (currentItem.colorants[0] === "Gray") { 
         if (colorsArray.toString().indexOf("Black") === -1) { 
          colorsArray.push("Black"); 
         } 
         alert("When this script is finished, please verify that the Ink/PMS table has the correct colors."); 
        } else { 
         if (colorsArray.toString().indexOf(currentItem.colorants[0]) === -1) { 
          colorsArray.push(currentItem.colorants[0]); 
         } 
        } 
       } else { 
        alert("The raster image in the art file must be a 1-channel bitmap and, thus, script cannot determine its color."); 
       } 
      } else if ((currentItem.fillColor || currentItem.strokeColor) && !currentItem.guides) { 
       // If the current object has either a fill or a stroke, continue. 
       if (currentItem.pathPoints.length > 2 || (currentItem.pathPoints == 2 && currentItem.stroked && currentItem..strokeWidth >= 0.1)) 
       { 
        // If the current object has 2 points and a good stroke, or more than two points, continue. 
        getColors(currentItem, colorsArray); 
       } 
      } else if (currentItem.typename === "CompoundPathItem") { 
       for (var c = 0; c < currentItem.pathItems.length; c++) { 
        if (currentItem.pathItems[c].pathPoints.length > 2 || (currentItem.pathItems[c].pathPoints == 2 && currentItem.pathItems[c].stroked && currentItem.pathItems[c].strokeWidth >= 0.1)) 
        { 
         // If the current object has 2 points and a good stroke, or more than two points, continue. 
         getColors(currentItem.pathItems[c], colorsArray); 
        } 
       } 
      } 
     } 
     return; 
    } 

    function getColors(currentItem, colorsArray) 
    { 
     try 
     { 
      var fillColorType = currentItem.fillColor.typename; 
      var strokeColorType = currentItem.strokeColor.typename; 
      $.writeln("fillColorType is " + fillColorType); 
      switch (fillColorType) { 
       case "CMYKColor": 
        if (currentItem.fillColor.cyan === 0 && currentItem.fillColor.magenta === 0 && currentItem.fillColor.yellow === 0) { 
         if (currentItem.fillColor.black > 0) { 
          if (colorsArray.toString().indexOf("Black") === -1) { 
           colorsArray.push("Black"); 
          } 
          if (currentItem.fillColor.black < 100) {bHalftones = true;} 
         } 
        } else { 
         // $.writeln("Four color process!"); 
         bFourCP = true; 
         bHalftones = true; 
        } 
        break; 
       case "GrayColor": 
        if (currentItem.fillColor.gray > 0) { 
         if (colorsArray.toString().indexOf("Black") === -1) { 
          colorsArray.push("Black"); 
         } 
         if (currentItem.fillColor.gray < 100) {bHalftones = true;} 
        } 
        break; 
       case "SpotColor": 
        if (colorsArray.toString().indexOf(currentItem.fillColor.spot.name) === -1 && currentItem.fillColor.spot.name.toLowerCase().indexOf("white") === -1) { 
         colorsArray.push(currentItem.fillColor.spot.name); 
        } 
        if (currentItem.fillColor.tint < 100) {bHalftones = true;} 
        break; 
       case "GradientColor": 
        bHalftones = true; 
        for (var j = 0; j < currentItem.fillColor.gradient.gradientStops.length; j++) { 
         var gStop = currentItem.fillColor.gradient.gradientStops[j].color; 
         switch (gStop.typename) { 
          case "GrayColor": 
           if (colorsArray.toString().indexOf("Black") === -1) { 
            colorsArray.push("Black"); 
           } 
           break; 
          case "SpotColor": 
           if (colorsArray.toString().indexOf(gStop.spot.name) === -1) { 
            colorsArray.push(gStop.spot.name); 
           } 
           break; 
          case "CMYKColor": 
           if (gStop.cyan === 0 && gStop.magenta === 0 && gStop.yellow === 0 && gStop.black > 0) { 
            if (colorsArray.toString().indexOf("Black") === -1) { 
             colorsArray.push("Black"); 
            } 
            if (gStop.black < 100) {bHalftones = true;} 
           } else if (gStop.cyan === 0 && gStop.magenta === 0 && gStop.yellow === 0 && gStop.black === 0) { 
            break; 
           } else { 
            // $.writeln("Four color process."); 
            bFourCP = true; 
            bHalftones = true; 
           } 
           break; 
          default: 
           // $.writeln("Four color process?"); 
           bFourCP = true; 
           bHalftones = true; 
         } 
        } 
        break; 
       case "NoColor": 
        break; 
       default: 
        // $.writeln("The fill color on object number " + i + " is of type " + fillColorType); 
      } 

      switch (strokeColorType) { 
       case "CMYKColor": 
        if (currentItem.strokeColor.cyan === 0 && currentItem.strokeColor.magenta === 0 && currentItem.strokeColor.yellow === 0) { 
         if (currentItem.strokeColor.black > 0) { 
          if (colorsArray.toString().indexOf("Black") === -1) { 
           colorsArray.push("Black"); 
          } 
          if (currentItem.strokeColor.black < 100) {bHalftones = true;} 
         } 
        } else { 
         // $.writeln("Four color process!"); 
         bFourCP = true; 
         bHalftones = true; 
        } 
        break; 
       case "GrayColor": 
        if (currentItem.strokeColor.gray > 0) { 
         if (colorsArray.toString().indexOf("Black") === -1) { 
          colorsArray.push("Black"); 
         } 
         if (currentItem.strokeColor.gray < 100) {bHalftones = true;} 
        } 
        break; 
       case "SpotColor": 
        if (colorsArray.toString().indexOf(currentItem.strokeColor.spot.name) === -1) { 
         colorsArray.push(currentItem.strokeColor.spot.name); 
        } 
        if (currentItem.strokeColor.tint < 100) {bHalftones = true;} 
        break; 
       case "GradientColor": 
        bHalftones = true; 
        for (var j = 0; j < currentItem.strokeColor.gradient.gradientStops.length; j++) { 
         var gStop = currentItem.strokeColor.gradient.gradientStops[j].color; 
         switch (gStop.typename) { 
          case "GrayColor": 
           if (colorsArray.toString().indexOf("Black") === -1) { 
            colorsArray.push("Black"); 
           } 
           break; 
          case "SpotColor": 
           if (colorsArray.toString().indexOf(gStop.spot.name) === -1) { 
            colorsArray.push(gStop.spot.name); 
           } 
           break; 
          case "CMYKColor": 
           if (gStop.cyan === 0 && gStop.magenta === 0 && gStop.yellow === 0 && gStop.black > 0) { 
            if (colorsArray.toString().indexOf("Black") === -1) { 
             colorsArray.push("Black"); 
            } 
            if (gStop.black < 100) {bHalftones = true;} 
           } else if (gStop.cyan === 0 && gStop.magenta === 0 && gStop.yellow === 0 && gStop.black === 0) { 
            break; 
           } else { 
            // $.writeln("Four color process."); 
            bFourCP = true; 
            bHalftones = true; 
           } 
           break; 
          default: 
           // $.writeln("Four color process?"); 
           bFourCP = true; 
           bHalftones = true; 
         } 
        } 
        break; 
       case "NoColor": 
        break; 
       default: 
        // $.writeln("The stroke color on object number " + i + " is of type " + strokeColorType); 
      } 
     } 
     catch (e) {/* If an error was found with the fill color and/or stroke color, then just skip this particular path item. */}; 
     return; 
    } 

    document.close(SaveOptions.DONOTSAVECHANGES); 

    // Now we combine the gathered items into a single array and return it. 
    if ((colorsArray.length > 1 && !/HI/.test(templateName.substring(0, 2))) || bFourCP) {bReg = true;} 
    prodInfo.push(templateName, colorsArray, bHalftones, bFourCP, bReg); 

    return prodInfo.toSource(); 
}; 

我知道它有點亂,現在,與調試的目的,其中一些甚至被註釋掉了,因爲他們造成的錯誤很多$.writeln秒。無論如何,我會非常感謝對此問題的任何幫助。

+0

你可以附加一個文件,在複合路徑的東西里有奇怪的'路徑? – CRGreen

回答

2

你的腳本不能看到所有pathItems因爲你的根是一個層,如果你改變

colorsInUse(document.layers[0]); 
to 
colorsInUse(document); 

你會看到所有pathItems,即使這包括compoundPath

0

通常裏面,創建在Illustrator中甚至不可能有兩組路徑。

但是,如果您創建一組一個路徑,請選擇此組和另一個路徑,製作此選擇的複合路徑,您將在compoundPath中獲得一個組。