• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Delete all text and pages 2 through end

Community Expert ,
Sep 28, 2020 Sep 28, 2020

Copy link to clipboard

Copied

Hi, After a long absence I am doing some InDesign JavaScript scripting on Windows with ID 2020. I have a document that someone is supplying me and I have to import text into it. I want to make sure that there is no existing text in the document and that any extra pages beyond page 1 are deleted. I figured out how to select all of the text but I am not sure how to delete it. Thank you in advance.

textFrame = doc.textFrames[0];
textFrame.parentStory.texts[0].select ();
// Not sure what to do here.
doc.selection.remove ();
TOPICS
Scripting

Views

307

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 28, 2020 Sep 28, 2020

It looks like this is what I need:

    // Delete all body page content.
    textFrame = doc.textFrames[0];
    textFrame.parentStory.texts[0].contents = "";

Votes

Translate

Translate
Community Expert ,
Sep 28, 2020 Sep 28, 2020

Copy link to clipboard

Copied

Try the following

for(var i = app.documents[0].pages.length - 1; i > 0 ; i--)
{
	app.documents[0].pages[i].remove();
}
app.documents[0].textFrames.everyItem().remove()

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 28, 2020 Sep 28, 2020

Copy link to clipboard

Copied

Thank you for the reply. I need to delete the text first or else it autoflows and adds the pages back in. I know how to select the text, but I don't know how to remove it. Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 28, 2020 Sep 28, 2020

Copy link to clipboard

Copied

It looks like this is what I need:

    // Delete all body page content.
    textFrame = doc.textFrames[0];
    textFrame.parentStory.texts[0].contents = "";

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 28, 2020 Sep 28, 2020

Copy link to clipboard

Copied

Hi frameexpert,

if I understand this right, in principle you want to remove all stories of the document.

And you want to restrict the number of pages of that document to the first one.

app.documents[0].stories.everyItem().remove();
app.documents[0].documentPreferences.pagesPerDocument = 1;

 

If you want to remove all text frames from spread one as well, you need additional code.

Also if you want not to remove text from master spreads.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 28, 2020 Sep 28, 2020

Copy link to clipboard

Copied

LATEST

Yes, thank you. I want to keep the first text frame so that I can import fresh context into the file. The template developer sometimes leaves sample content in the document.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines