• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to find textframes that cross the page margins

New Here ,
May 30, 2020 May 30, 2020

Copy link to clipboard

Copied

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];
            // alert(singlePage.textFrames.length);
            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 ();
                }
                
            }              
        }
    
}

 

TOPICS
Bug

Views

240

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 01, 2020 Jun 01, 2020

Copy link to clipboard

Copied

LATEST

I think the problem is in the margins array declaration. how do i declare it properly for each page in the spread?

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines