我是一名经验丰富的JavaScript程序员,目前正在从事一个需要大量工作的项目,我希望这个过程可以使用InDesign的脚本进行自动化。
本质上,这就是我想要做的。我有一个5(有时,但很少,4)-digit字符串。然后,我在文本框架下有三个矩形,我想根据数字的最后一个数字对它们应用一个样本。数字0-9被分配了一种特定的颜色(和样本),目前我正在手动遍历每个矩形,并根据最后两个数字选择它,然后将样本应用于所有选定的矩形。
我确信一定可以使用InDesign用户脚本自动执行这个过程,但我对此并没有很好的理解。下面是一个如何将颜色分配给特殊条形码的示例:
0=红色1=蓝色2=绿色....
因此,对于下面的代码: 12312,我希望下面的条具有以下颜色:
蓝色、红色、蓝色
(即顶部和底部行=倒数第二位;中间行=最后一位)。
有没有人可以告诉我,我如何编写一个脚本,循环我的文档中的页面,找到代码,提取最后两位数字,然后根据数字将样本应用于rectangle对象……
我相信我可以使用常规的JavaScript和超文本标记语言来编写类似的东西,但话虽如此,我对超文本标记语言中的DOM很熟悉……
如有任何帮助或建议,我们将不胜感激!
发布于 2011-05-05 02:03:58
这是我快速输入的一个脚本示例,应该可以帮助您入门。您可能需要对其进行调整,但我认为它满足了您的要求。
test();
function test(){
//Open your document:
var myDoc = app.open('c:/users/user/desktop/test.indd');
//Get all groups for this document:
var myGroups = myDoc.groups;
//Get all swatches for this document:
var mySwatches = myDoc.swatches;
//Loop through all of your groups:
for (var i = 0; i < myGroups.length; i++){
//for each group we need to get the code from the text frame,
//so get the text frame first:
var myTextFrame = myGroups[i].textFrames[0];
//Now get the color code from the text frame:
var myColorCode = myTextFrame.contents;
//get the rectangle from this group:
var myRect = myGroups[i].rectangles[0];
//here you would want to parse out whichever digits you need from myColorCode
//use the code to determine which swatch to use, loop through the swatches:
for(var s = 0; s < mySwatches.length; s++){
//find it:
var mySwatch = mySwatches[s];
//apply this swatch to your rectangle, and leave the loop:
myRect.fillColor = mySwatch;
break;
}
}
}我希望这能帮到你!这里有一些应该会有帮助的scripting references straight from Adobe。如果你对上面的例子有任何疑问,请告诉我。
https://stackoverflow.com/questions/5885918
复制相似问题