2014-11-05 88 views
0

我試圖在Illustrator中爲compoundPathItem內的pathItems着色。我的物體看起來像一個圓圈內的一個圓圈。在compoundPathItem內沒有筆畫,四條路徑,兩個compoundPathItems如何給Illustrator CS5添加顏色嵌套複合路徑Extendscript?

當調試這條線:警報(doc.compoundPathItems [0])I get:-[CompoundPathItem] .... which makes sense because I've combined two compoundPathItems.

不過,我似乎無法獲取到pathItems訪問,以便它們上色:

doc.compoundPathItems[0].compoundPathItems[0].pathItems ... errors out x_x ... 
alert(doc.compoundPathItems[0].pathItems.length) gives me 0 .... T-T 

幫助我明白這裏發生了什麼。

回答

0

是像一個概述的字母「O」的對象'形狀?或「◎」>一個compoundPathItem中的兩個compoundPathItems

我認爲最後着色的compound_path_item的任何path_item都會填充顏色父對象(= compound_path_item)。

如果字母「O」,請嘗試以下

#target "Illustrator" 
var doc = app.documents[0]; 
var co_pathitem = doc.compoundPathItems[0].pathItems; 

// create colors 
var color1 = new RGBColor(); 
color1.red = 255; 

var color2 = new RGBColor(); 
color2.blue = 255; 

// fillcolor red 
co_pathitem[0].filled = true; 
co_pathitem[0].fillColor = color1; 
$.writeln(co_pathitem[0].fillColor.properties()); // => color1 

// fillcolor blue 
co_pathitem[1].filled = true; 
co_pathitem[1].fillColor = color2; 
$.writeln(co_pathitem[1].fillColor.properties()); // => color2 

// => doc.compoundPathItems[0] will be colored with color2(colored at last) 

// but pathItems[0] filled with color1 yet 
$.writeln(co_pathitem[0].fillColor.properties()); // => color1 

Object.prototype.properties = function (cr) { 
    var self = this; 
    var cr = cr || ", "; 
    var props = []; 
    for (var i in self) { 
    try { 
     props.push(i + ":" + self[i]); 
    } catch (e) { 
     // props.push(i + ":" + e); 
    } 
    }; 
    return props.join(cr); 
} 
+0

不,對不起..形狀就像你說的第二個「◎」 – 2014-11-25 22:29:20

0

這個代碼,如果所有pageItemscompoundItems這個腳本會工作,app.activeDocument.pathItems會給文檔中的所有pathItems。它也將嵌套在compoundPathItem。所以試試它是否適合你

var currentDocument = app.activeDocument; 
var pathItems = currentDocument.pathItems; 
var redSwatch = currentDocument.swatches.getByName('CMYK Red'); 
var blueSwatch = currentDocument.swatches.getByName('CMYK Blue'); 
for (var i = 0; i < pathItems.length; i++) { 
    pathItems[i].filled = true; 
    pathItems[i].fillColor = redSwatch.color; 
    pathItems[i].stroked = true; 
    pathItems[i].strokeColor = blueSwatch.color; 
}