InDesign 脚本编写 - 初学者

发布于 2024-11-05 05:32:30 字数 597 浏览 2 评论 0原文

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

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

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

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

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

蓝色 红色的 蓝色

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

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

我有信心我可以使用常规 JavaScript 和 HTML 编写类似的内容,但话虽如此,我熟悉 HTML 中的 DOM...

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

I am a seasoned JavaScript programmer, and am currently working on a project which requires a lot of work, and I'm hoping that the process can be automated using scripts for InDesign.

Essentially, here's what I want to do. I have a 5 (sometimes, but rarely, 4)-digit string. I then have three rectangles underneath the text frame which I would like to apply a swatch to, depending on the final digits of the number. Numbers 0-9 are assigned a specific colour (and swatch), and at the moment I am manually going through each rectangle, and selecting it according to the last two digits, and applying the swatch to all those selected.

I am convinced that it must be possible to automate the process using InDesign User Scripts, but I don't have a good understanding of this. Here's an example of how the colours are assigned to the special bar codes:

0 = red
1 = blue
2 = green
....

So for the following code: 12312, I would like the bars underneath to have the following colours:

blue
red
blue

(i.e. top and bottom row = penultimate digit; middle row = last digit).

Could anyone indicate to me how I might write a script which loops through the pages in my document, finds the codes, extracts the last two digits and then applies a swatch to the rectangle object, depending on the number...

I am confident that I could write something like this using regular JavaScript and HTML, but that having been said, I am familiar with the DOM in HTML...

Any help or pointers would be gratefully received!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∝单色的世界 2024-11-12 05:32:30

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

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 的脚本参考,应该会有所帮助。如果您对上述示例有任何疑问,请告诉我。

Here is a script example I just typed up quick that should get you started. You may have to tweak it, but I think it covers what you're requesting.

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

    }


}

I hope this helps! Here are some scripting references straight from Adobe that should help. Let me know if you have any questions about the example above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文