This is a problem I've ignored for a long time...
Say I have a script that deletes all empty text frames. It's easy to
find an empty text frame with something like:
if (myFrame.characters.length < 1) -- the frame is empty!
But ... this doesn't work for 2 cases (at least, that I can think of):
(1) If the text frame contains the second half of a footnote that is
continued from a previous text frame(s); (2) if the text frame contains
the second half of a table that is continued from a previous text frame(s).
In both these cases (where the frame ONLY contains the second half of a
table or footnote), the simple way of checking whether the frame is
empty (as I showed above) returns a false positive -- the character
length of the frame is 0, but the frame is NOT empty.
Any idea how to solve this?
Especially with continuation tables, this is tricky and messy, and CS5+ require different approaches than earlier versions. If you are deleting frames from the end of the textContainers array, maybe you can delete frames until the last frame oversets. If it does, put the frame back.
It's probably easier to unthread the last frame. If the previous frame does not overset, delete the last frame; if it does overset, restore the thread.
Unthreading and checking for overset sounds like a practical idea,
thanks. A bit slow, though, probably.
Focusing on footnotes for a second: Text frames have a footnotes
property. So if I find a blank frame that has a previous frame, I could
get the last footnote (if there are any) with
myPrevTextFrame.footnotes[-1]. Now, I see that footnotes themselves have
a textFrames property. I was hoping that myFootnote.textFrames would
give me an array of all the textFrames which the footnote traverses. So
it would then be easy enough: if the last footnote of the previous text
frame contains 2 or more textFrames, then this frame is not empty.
Except that it doesn't work. myFootnote.textFrames doesn't seem to do
what I thought. In fact, I don't know what it does do. What is a
So right now, your idea of checking for oversets after unthreading is
the only way to do it that I know. And it's not ideal.
Ah... I've just got another idea. How about inserting an anchored object
into the last insertionPoint of the last footnote of the previous frame?
I think it should be possible to get its parentPage. Perhaps that's
quicker than unthreading!
Any other ideas?
Footnote.textFrames is the collection of all text frames that are anchored/inline to the footnote.
This empty frame thing is a real challenge. If you have a table that spans more than two frames, the intermediate frames that only contain part of a table are a pain to identify (I guess the same is true of partial footnotes, although such long footnotes don't come up so often as long tables do.
With CS5+, you can get
I believe that will get you an array of the text frames visited by the paragraph holding the table.
Hmm. I wonder what happens if you use:
That will probably run rather slowly, but it should give you a highly repetitive array of all the text frames visited by the story.
Doesn't solve the footnotes issue though.
Can"t Logical Reasoning solve this?
A text frame is empty if (a) it is not connected to a next or previous text frame, and (b) it has no contents. Safe to delete.
If (b) is true but (a) not, skip this one and go to the last frame in this thread. If it *seems* to be empty, delete it and check the *previous* frame for Overset Text. If not .. it was empty after all! Then continue with that frame.
Don't loop over text frame, loop over Stories, so you'll visit each frame only once.
What does "it has no contents" mean? Contents of ""?
If you have:
Empty Frames at end
Then the overset test will work only if you cycle backwards through the text containers of the story. Must get rid of those at the end before looking at those in the middle.
A text frame in the middle can be empty because of a text wrap. I guess it's a question of whether or not you want to delete those too. If not, then work from the end of a story until you find a frame that is not empty and then, almost by definition, all the previous frames are not empty -- although even in this scenario you could have a very small frame that is empty because there isn't space in it for even one character.
@Dave – and there is another case we have to consider:
An empty text frame that is not meant to be a text frame at all. E.g. a rectangle, that the user transformed inadvertantly to a text frame by clicking into it with the text tool. If you remove one of those you could wreck the layout…
Europe, Middle East and Africa