2016-06-22 10 views
0

我有一个插图文档,其上有各种文本和路径项目。我想遍历所有的文本项目,并改变它们的颜色和几个属性。然后根据项目名称,我想将它与其他具有相同名称的项目分组。我有一个几乎可以工作的脚本。问题是它留下了一些项目,或者不一致地忽略它们。有时它会影响它们,有时它会忽略它们。理解的任何帮助,下面的脚本在文本项目中循环插画页面

//Selects the graph before to scale them and turns off the pixel align so that values of 1 decimal place can be applied to strokes 
doc.selectObjectsOnActiveArtboard(); 
var sel = doc.selection; 
sel.pixelAligned=false 

var item 

var xLabels = layer.groupItems.add(); //create group for xAxis 
xLabels.name="xLabels" 
var yLabels = layer.groupItems.add(); //create group for xAxis 
yLabels.name="yLabels" 
var yTicks = layer.groupItems.add(); //create group for xAxis 
yTicks.name="yTicks" 

//Loops through ungrouped text items and set horizontal scale, spot black and tabular lining on figures 
for (var i = 0; i < layer.textFrames.length; i++) { 
    item=layer.textFrames[i]; 
    $.writeln (item) 
    item.textRange.characterAttributes.textFont = textFonts.getByName("Metric-Regular"); 
    item.textRange.characterAttributes.figureStyle=FigureStyleType.TABULAR 
    item.textRange.characterAttributes.fillColor=myBlack; 

    //move labels on xAxis into the same group 
    if (item.name=="xAxisLabel") { 
     item.moveToEnd(xLabels); 
    } 

    //move labels on yAxis into the same group 
    if (item.name=="yAxisLabel") { 
      item.moveToEnd(yLabels); 
    }; 

}; 

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

    if (item.name=="yAxisTick") { 
      item.moveToEnd(yTicks); 
    }; 
}; 

回答

0

的解决方案是扭转循环。基本上,当您将项目移动到一个组中时,它会更改页面上“松散”文本项的数量,以便循环长度在中途有效更改。对此的良好视觉解释可以在https://forums.adobe.com/thread/2171307找到,我也发布了问题