How to determine if a page is blank?

Community Beginner ,
Aug 13, 2018 Aug 13, 2018

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

232

Likes

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

Adobe Community Professional , Aug 13, 2018 Aug 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...

Likes

Translate

Translate
Adobe Community Professional ,
Aug 13, 2018 Aug 13, 2018

Copy link to clipboard

Copied

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;

    }

}

Likes

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
Community Beginner ,
Aug 13, 2018 Aug 13, 2018

Copy link to clipboard

Copied

LATEST

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

Likes

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