首页 > 解决方案 > 用于查找与边距重叠的文本框的 Indesign 脚本

问题描述

该答案带来了一个脚本来查找重叠的文本框。现在我尝试调整脚本以查找跨页边距的文本框,但脚本无法正常工作,并且它会提醒双页右侧页面上的所有文本框作为通过页面的文本框边距,我无法弄清楚原因以及如何正确定义它的代码。

也许问题在于我如何设置pageMargins包含我的边距位置的数组?

以下是我的代码:

// find all out of margins textFrames

app.activeDocument.viewPreferences.rulerOrigin= RulerOrigin.SPREAD_ORIGIN;
//If you are going to work with pages, not spreads, change the line above to PAGE_ORIGIN;
for (a = 0; a < app.activeDocument.spreads.length; a ++) {
    var pg = app.activeDocument.spreads [a];
        for (e = 0 ; e < pg.pages.length; e ++) {
            var singlePage = pg.pages[e];

            for (b = 0 ; b < singlePage.textFrames.length; b ++) {
                var r1 = pg.textFrames [b];
                var gb1 = r1.geometricBounds;
                var pageMargins = [singlePage.bounds [0] + singlePage.marginPreferences.top,
                                singlePage.bounds [1] + singlePage.marginPreferences.left,
                                singlePage.bounds [2] - singlePage.marginPreferences.bottom,
                                singlePage.bounds [3] - singlePage.marginPreferences.right
                    ];

                // check if it's overlapping page margins        
                if(!(gb1 [0] > pageMargins [0] && gb1 [1] > pageMargins [1] && gb1 [2] < pageMargins [2] && gb1 [3] < pageMargins [3]))
                {
                    r1.select ();
                    alert("frame geometric bounds: " + gb1 + "\npage Margins: " + pageMargins + "\nnumber in spread: " + e + "\nsingle page bounds: " + singlePage.bounds + "\n")
                    var cnf = confirm ("Text frames overlap. Continue searching?", true, "Overlapping text frames");
                    if (!cnf)
                        exit ();
                }

            }              
        }

}

标签: javascriptadobe-indesignextendscript

解决方案


推荐阅读