0

That answer brought a script to find overlapping text boxes. And now I tried to adjust the script to find text boxes that cross the page margin, but the script does not work properly, and it alerts all the text boxes on the right-hand page of the double page as those that go through the page's margin, and I can't figure out the reason and how to define it correctly The code.

Maybe the problem is with how I set the array pageMargins that includes my margin location?

The following is my code:

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

            }              
        }

}
RobC
  • 22,977
  • 20
  • 73
  • 80
i. Madar
  • 1
  • 1
  • This works for me with no problem. I dropped confirm function call as I do not have the function and you need semicolon after the alert. There is something else with your set up we can't see. I tested it on Indesign 2020 – Nicolai Kant Jun 07 '20 at 13:54
  • @NicolaiKant Perhaps this has to do with the fact that my ID version is the ME version and the book from right to left. In any case, I was suggested to change line ```var r1 = pg.textFrames [b];``` to ```var r1 = singlePage.textFrames[b];``` and it works well for me, because this is how it relates to the collection of text frames for each page individually. – i. Madar Jun 10 '20 at 18:08
  • This makes sense, well spotted. My quick test worked as I didn't not have many spreads and frames – Nicolai Kant Jun 10 '20 at 22:14

0 Answers0