1

I have been using the DeleteEmptyFrames.jsx script from the interwebz and it works in text frames containing nothing, but fails when the frame had a data merge field that contained no data when merging, so it has this hidden chars, like two semicolons, that represent the field marker. Empty frame with :: hidden data merge field marker Here is the code of the script:

var myStories = app.activeDocument.stories.everyItem().getElements();
for (i = myStories.length - 1; i >= 0; i--){
    var myTextFrames = myStories[i].textContainers;
    for (j = myTextFrames.length - 1; j >= 0; j--)    {
        if (myTextFrames[j].contents == ""){
            myTextFrames[j].remove();
        }
    }
}

How do I say "the frame contents are non-word characters" so I can remove the frame?

  • The fastest way, which doesn’t require altering the script, would be to edit such a frame in the Story Editor, copy one of these markers, use Find and Replace to remove them from the document, and then run the script. (Unless they’re not selectable in the Story Editor? I don’t think I’ve ever tried, so I don’t know if they are.) – Janus Bahs Jacquet Sep 11 at 7:52
  • 1
    There is indeed a way to find these markers with the Find dialog. Just look for <FEFF> and the markers are detected. But altering the script with myTextFrames[j].words.length == 0 does the trick. Thanks anyway! – Aris Sep 12 at 13:56
2

Apparently it was a simple way to do it. Just check if the words total length is 0, even when the frame is not empty. Non-word characters like the data markers, even if there are many of them, amount to a total of zero words, hence:

var myStories = app.activeDocument.stories.everyItem().getElements();
for (i = myStories.length - 1; i >= 0; i--){
    var myTextFrames = myStories[i].textContainers;
    for (j = myTextFrames.length - 1; j >= 0; j--)    {
        if ((myTextFrames[j].contents == "") || (myTextFrames[j].words.length == 0)){
            myTextFrames[j].remove();
        }
    }
}

Hope this helps to anyone trying to accomplish the same. Greetings!

  • Good job on figuring it out! Thanks for leaving your answer in :) – curious Sep 12 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.