Skip to content


InDesign Tip 2. Removing Empty Frames

Perusing an InDesign discussion I found recommendations for a better InDesign scripting API: http://jongware.mit.edu/idcs6js/ For my style of development, the documentation feels cleaner and more organized. One thing I really do like is that the documentation prominently displays the class hierarchy.

With a better understand I was able to take a code snippet that removes empty frames from this discussion by a user named Harbs, and update it to fit my needs for Adobe CS6. The main difference from the original script is the sequence of API calls you use to obtain all the page items (line #6). The other thing I did was to extend the code to include all other immediate children of the class PageItem. While my focus right now is to remove empty text frames, I want to be prepared to extend the code if I encounter other types of empty frames while I’m using this script. Here is the script in its full entirety. Enjoy!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
    * Remove Empty Frames
    **/
var count = 0;
var doc = app.documents.item(0);
var pageitems = doc.allPageItems;
 
while (frame = pageitems.pop()) {
    if (frame instanceof EPSText)          {continue; }
    else if (frame instanceof FormField)   {continue; }
    else if (frame instanceof Graphic)     {continue; }
    else if (frame instanceof Group)       {continue; }
    else if (frame instanceof HtmlItem)    {continue; }
    else if (frame instanceof MediaItem)   {continue; }
    else if (frame instanceof SplineItem)  {continue; }
    else if (frame instanceof TextFrame){
        if (frame.contents == "") {
            count++;
            frame.remove();
        }
        continue;
    }
}
alert( 'Removed empty Frames: ' + count + '\n');

Posted in InDesign. Tagged with , .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.