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.
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
...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;
}
}
Copy link to clipboard
Copied
Thanks Rick, this works perfectly. You definitely are the FM Scripting master. Others please don't take offense, you're pretty good too.