Scripting InDesign - Beginner

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 19:37:57

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!