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

ExtendScript - Delete Disconnected Flow Pages

Engaged ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

This will be a tough two part question.
With one template, we are having an issue where if you add a page break, FM will add disconected flow pages. For example, in a 9-page file, pages 6 and 8 will have headers and footers from the master page, but they will not have the dotted text border for the main flow content. So they aren't technically "Blank" pages.
It seems to mostly happen before and after art pages (Page 7 has an anchored frame with an image on it.)

Saving the file does not clear the pages. Manually selecting the pages does - i.e. Format>Document>Delete pages.
But I would prefer to have a script so that I don't have to manually notice and remove the pages.
Question 1: What causes this and how can it be stopped from happening.
Question 2: I'm not sure how to prevent this. I found a script called RemoveEmptyPages from the .zip file at https://www.daube.ch/docu/fmaker88.html That is designed to just delete empty pages at the end of the document and then stop. I tried modifying it to go back through the document and noticed two things:
I added an alert to tell me the page number and it started at 8 (correct since FM starts numbering at 0) and then after .PagePrev, it went to 0 - possibly b/c it didn't recognize Page 7 b/c it wasn't in the same flow. Then the script didn't work, b/c it checks for paragraphs in the text frame and it couldn't find a text frame.
I'm not sure if I should be looking for .PagePrev is more than one number less than the original page and then deleting or looking to GetFrame is not valid object and then deleting.
Also - basically I just want to delete disconnected pages, there may be valid blank pages in the document that I don't want to delete.

 

TOPICS
Scripting

Views

410

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

correct answers 1 Correct answer

Engaged , May 18, 2023 May 18, 2023

page2.Delete();

works.

Here's the corrected script:

function RemoveEmptyPages(doc){
    var mainFlow, page, textFrame;
//    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        // Get the document's main flow.
        mainFlow = doc.MainFlowInDoc;
        // Loop through each page in the document.
        page = doc.FirstBodyPageInDoc;
        while (page.ObjectValid () === 1) {
            // Get the A flow text frame on the page.
            textFrame = getTextFrame (page, "A");
    
...

Votes

Translate

Translate
Community Expert ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

re: … if you add a page break …

This task needs re-think from the top, so to speak. Why are people using
  Insert â–¼ Page Break… â—‹ {location} [Set]
and what is it they really need to do?

FM has no data object for page break. What that menu option does, is apply a /Pagination\ override to the currently selected paragraph. Overrides are pretty much the opposite of best practices in FM. They can silently vanish in the wake of a number of common operations.

 

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
Engaged ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

@Bob_Niland

 

In theory, I agree with you. In practice, we use a LOT of conditional text and it is common to need a paragraph on a new page for one set of condition tags and when you change them, that paragraph has two-thirds of a blank page in front of it.
There is a LOT that can be done with Para>Keep with next and widow/orphan control settings, but not always all of it.

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
Engaged ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

Was looking on the related tab and I think this answers my question - need to test it out, though: https://community.adobe.com/t5/framemaker-discussions/how-to-detect-disconnected-pages/td-p/12230135

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
Engaged ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

Okay, I'm close to a solution, but I'm not quite there yet.

I don't fully understand what is going on in the code in the other thread, specifically:

if (textFrame) {

It seems like this should technically be:

if(textFrame.ObjectValid===1){

But it seems to work.

$.writeln ("Disconnected page: " + page.PageNumString);

It seems like the above writes to the javascript console (or somewhere), which if fine if you want to FIND the pages, I want to remove them.

It looks like Rick's script is finding pages with a text flow on them, but it is not the main flow. My pages don't have a text flow at all.

GetTextFrame works. I added an alert and on the "Disconnected" pages, it just jumped down to the next page statement, so I think I need something like this:

function RemoveEmptyPages(doc){
    var mainFlow, page, textFrame;
//    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        // Get the document's main flow.
        mainFlow = doc.MainFlowInDoc;
        // Loop through each page in the document.
        page = doc.FirstBodyPageInDoc;
        while (page.ObjectValid () === 1) {
            // Get the A flow text frame on the page.
            textFrame = getTextFrame (page, "A");
            if (textFrame) {
                // See if the text frame's flow is the main flow.
                if (textFrame.Flow.id !== mainFlow.id) {
                    // If not, you have a disconnected pageg.
                    $.writeln ("Disconnected page: " + page.PageNumString);
                }
            }
            else
            {
                // page.Delete
                }
            page = page.PageNext;
            alert("Page = " + page.PageNumString)
        }
    }
}

See the else block and the Page.Delete, but I'm not sure if Page.Delete is the correct command, and if I delete it, the Page.PageNext will probably fail.  Maybe I need another variable.

var page2=page
page=page.PagePrev

page2.Delete

???

 

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
Engaged ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

I don't think page2.Delete is the proper command. My test file has an issue on page 4, and the else statement keeps sending it page to Page 3 and then the next statement sends it on to Page 4 etc., but if it deleted page 2, it would probably work!!!

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
Engaged ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

LATEST

page2.Delete();

works.

Here's the corrected script:

function RemoveEmptyPages(doc){
    var mainFlow, page, textFrame;
//    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        // Get the document's main flow.
        mainFlow = doc.MainFlowInDoc;
        // Loop through each page in the document.
        page = doc.FirstBodyPageInDoc;
        while (page.ObjectValid () === 1) {
            // Get the A flow text frame on the page.
            textFrame = getTextFrame (page, "A");
            if (textFrame) {
                // See if the text frame's flow is the main flow.
                if (textFrame.Flow.id !== mainFlow.id) {
                    // If not, you have a disconnected pageg.
                    $.writeln ("Disconnected page: " + page.PageNumString);
                }
            }
            else
            {
                // page.Delete
                var page2 = page;
                page=page.PagePrev;
                page2.Delete();
                }
            page = page.PageNext;
            //alert("Page = " + page.PageNumString)
        }
    }
}
function getTextFrame (page, flow) {
    var frame, graphic;
    frame = page.PageFrame;
    graphic = frame.FirstGraphicInFrame;
    while (graphic.ObjectValid () === 1) {
        if (graphic.constructor.name === "TextFrame") {
            if (graphic.Flow.Name === flow) {
                return graphic;
            }
        }
        graphic = graphic.NextGraphicInFrame;
    }
}

If you wanted to delete EITHER pages with no flow or pages with a different flow, I think you could copy the added lines under the else block after the $writeln line and that would probably work.

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