Skip to main content
Inspiring
April 20, 2017
Answered

How do I delete all text frames using javascript

  • April 20, 2017
  • 3 replies
  • 2652 views

I trying to set up code at the beginning of my script that will look and see if there is a text frame in the document (it will have text in it but I'm not sure if its relevant), and if it exists delete it.

Does anyone have an idea if this can be done?

Thanks,

~David

This topic has been closed for replies.
Correct answer Obi-wan Kenobi

app.activeDocument.textFrames.everyItem().remove();

(^/)

3 replies

Inspiring
April 20, 2017

These both worked well, thank you so much!

Obi-wan Kenobi
Obi-wan KenobiCorrect answer
Legend
April 20, 2017

app.activeDocument.textFrames.everyItem().remove();

(^/)

Anantha Prabu G
Legend
April 20, 2017

Hi,

Try this code.

var myDoc = app.activeDocument;

var myStories = app.activeDocument.stories.everyItem().getElements();  

        for (i = myStories.length - 1; i >= 0; i--){  

            var myTextFrames = myStories.textContainers;  

            for (j = myTextFrames.length - 1; j >= 0; j--){  

            myTextFrames.remove();  

            }  

        } 

Design smarter, faster, and bolder with InDesign scripting.