1

我是一位经验丰富的 JavaScript 程序员,目前正在从事一个需要大量工作的项目,我希望可以使用 InDesign 脚本自动化该过程。

本质上,这就是我想要做的。我有一个 5(有时,但很少是 4)位字符串。然后,我在文本框架下方有三个矩形,我想将样本应用到这些矩形,具体取决于数字的最终数字。数字 0-9 被分配了一种特定的颜色(和色板),目前我正在手动遍历每个矩形,并根据最后两位数字选择它,并将色板应用于所有选定的对象。

我确信必须可以使用 InDesign 用户脚本自动化该过程,但我对此没有很好的理解。以下是如何将颜色分配给特殊条形码的示例:

0 = 红色 1 = 蓝色 2 = 绿色 ....

因此,对于以下代码:12312,我希望下面的条具有以下颜色:

蓝色 红色 蓝色

(即顶行和底行 = 倒数第二个数字;中间行 = 最后一个数字)。

谁能告诉我如何编写一个脚本,该脚本循环遍历文档中的页面,找到代码,提取最后两位数字,然后根据数字将样本应用于矩形对象...

我相信我可以使用常规的 JavaScript 和 HTML 编写类似的东西,但话虽如此,我对 HTML 中的 DOM 很熟悉......

任何帮助或指点将不胜感激!

4

1 回答 1

3

这是我刚刚快速输入的一个脚本示例,应该可以帮助您入门。您可能需要对其进行调整,但我认为它涵盖了您的要求。

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;
        }

    }


}

我希望这有帮助!以下是直接来自 Adob​​e的一些脚本参考,应该会有所帮助。如果您对上述示例有任何疑问,请告诉我。

于 2011-05-04T18:03:57.880 回答