ExtendScript - Delete Disconnected Flow Pages
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.
