脚本InDesign - 初学者 [英] Scripting InDesign - Beginner

查看:213
本文介绍了脚本InDesign - 初学者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名经验丰富的JavaScript程序员,目前正在开展一项需要大量工作的项目,我希望使用InDesign脚本自动完成该过程。

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.

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

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.

我确信必须能够使用InDesign用户脚本自动执行该过程,但我对此并不十分了解。以下是如何将颜色分配给特殊条形码的示例:

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 =红色
1 =蓝色
2 =绿色
....

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

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

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...

我相信我可以使用常规JavaScript和HTML编写类似的东西,但是已经说过了,我很熟悉HTML中的DOM ...

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!

推荐答案

这是一个脚本示例,我只是快速输入,应该让你开始d。您可能需要调整它,但我认为它涵盖了您要求的内容。

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

    }


}

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

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.

这篇关于脚本InDesign - 初学者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆