Skip to main content
Known Participant
August 13, 2018
Answered

How to determine if a page is blank?

  • August 13, 2018
  • 1 reply
  • 584 views

Trying to create a script to determine if a page is blank.

Been thinking on scrolling through the BodyPage collection but not sure how to link that to the actual flow.

Any ideas I can start with?

Thanks.

This topic has been closed for replies.
Correct answer frameexpert

I use a series of dependent functions to determine if a page is empty. The example here tests the current page, but you can expand it to test all of the pages in a document. Note that this code considers a page empty if there is nothing in its Flow A text frame. Technically, there could be other text frames or graphics directly on the page and this script doesn't check for this. But in most cases, you are looking for a page with nothing in its Flow A text frame so this will work fine. Please let me know if you have any questions or comments.

#target framemaker

var doc = app.ActiveDoc;

// Test the current page.

var page = doc.CurrentPage;

// true for empty; false for not empty.

alert (pageIsEmpty (page));

function pageIsEmpty (page) {

   

    var textFrame;

   

    textFrame = getTextFrame (page, "A");

    if (textFrame) {

        if (textFrameIsEmpty (textFrame) === true) {

            return true;

        }

    }

    return false;

}

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;

    }

}

function textFrameIsEmpty (textFrame) {

   

    if (textFrame.LastPgf.ObjectValid () === 1) {

        return false;

    }

    else if (textFrame.LastCell.ObjectValid () === 1) {

        return false;

    }

    else if (textFrame.LastAFrame.ObjectValid () === 1) {

        return false;

    }

    else if (textFrame.LastFn.ObjectValid () === 1) {

        return false;

    }

    else {

        return true;

    }

}

1 reply

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
August 13, 2018

I use a series of dependent functions to determine if a page is empty. The example here tests the current page, but you can expand it to test all of the pages in a document. Note that this code considers a page empty if there is nothing in its Flow A text frame. Technically, there could be other text frames or graphics directly on the page and this script doesn't check for this. But in most cases, you are looking for a page with nothing in its Flow A text frame so this will work fine. Please let me know if you have any questions or comments.

#target framemaker

var doc = app.ActiveDoc;

// Test the current page.

var page = doc.CurrentPage;

// true for empty; false for not empty.

alert (pageIsEmpty (page));

function pageIsEmpty (page) {

   

    var textFrame;

   

    textFrame = getTextFrame (page, "A");

    if (textFrame) {

        if (textFrameIsEmpty (textFrame) === true) {

            return true;

        }

    }

    return false;

}

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;

    }

}

function textFrameIsEmpty (textFrame) {

   

    if (textFrame.LastPgf.ObjectValid () === 1) {

        return false;

    }

    else if (textFrame.LastCell.ObjectValid () === 1) {

        return false;

    }

    else if (textFrame.LastAFrame.ObjectValid () === 1) {

        return false;

    }

    else if (textFrame.LastFn.ObjectValid () === 1) {

        return false;

    }

    else {

        return true;

    }

}

www.frameexpert.com
fonrigAuthor
Known Participant
August 13, 2018

Thanks Rick, this works perfectly. You definitely are the FM Scripting master. Others please don't take offense, you're pretty good too.