0

I wrote a script that should find and alert on every textframe that overlapping the page margins on some side. But the problem is that the script also identifies textframes that are inside the margins, as if they are out of the margins of the second page in the spread, even though in the code I treat each page from the spread seperatley, rather than as a whole spread.

I tried to change a few things, but I can't isolate the problem. Does anyone have any idea where my mistake is in this script? Thanks in advance to the respondents.

// 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 ();
                }

            }              
        }

}
  • 1
    Not sure if that is the actual issue, but shouldn't the line var r1 = pg.textFrames [b]; rather be var r1 = singlePage.textFrames[b];? Otherwise this would refer to the text frames collection on the spread instead of the single page that you're handling in that moment. – mdomino Jun 3 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.