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

Delete paragraphs from a text frame except first para

Engaged ,
Aug 17, 2022 Aug 17, 2022

From a text frame which is linked to two or three frames, I want to delete all paragraphs excpet first one. I have already done using below code but looking for shorter code (without using for loop) if possible.

var i;

var myDoc = app.activeDocument;

var myFrame = myDoc.textFrames.itemsByName("virender");

var my_count = myFrame.parentStory.paragraphs.length;

for (i = my_count; i > 1; i--) {

myFrame.parentStoryparagraphs.item(i-1).contents = "";

}

TOPICS
Scripting
304
Translate
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 , Aug 17, 2022 Aug 17, 2022

And without a for-loop (but why?):

app.activeDocument.textFrames.item('virender')
  .paragraphs
  .itemByRange (1, -1)
  .remove();
Translate
Community Expert ,
Aug 17, 2022 Aug 17, 2022

If you want shorter code, use this:

par = app.activeDocument.textFrames.item('virender').paragraphs.everyItem().getElements();
for (i = par.length-1; i > 0; i--) {
  par[i].contents = '';
}

P.

Translate
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 ,
Aug 17, 2022 Aug 17, 2022

And without a for-loop (but why?):

app.activeDocument.textFrames.item('virender')
  .paragraphs
  .itemByRange (1, -1)
  .remove();
Translate
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 ,
Aug 17, 2022 Aug 17, 2022

Hi Peter,

did not see your latest reply with the itemByRange() code.

 

Best,

Uwe Laubender
( Adobe Community Professional )

Translate
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
Engaged ,
Aug 17, 2022 Aug 17, 2022

Hi Peter,

Thank you. I wanted to use it without for loop because I felt that there could be a effieient way do doing instead of using revsere loop etc.
Your code and this one => myFrame.parentStory.paragraphs.itemByRange(1,-1).contents = ""; worked like a magic. Thank you again.

Translate
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 ,
Aug 17, 2022 Aug 17, 2022

Hi @virender_CTS ,

let's assume you want to remove all paragraphs in red of this situation:

TextFrameVirenderSelected-1.PNG

So that the result is this:

TextFrameVirenderParagraphsRemoved-2.PNG

Then you could use this code:

app.documents[0].textFrames.itemByName("Virender").
texts[0].paragraphs.itemByRange( 1,-1).remove();

 

Also note that in a situation like that, when the said text frame has overset text and is the last one in the story:

TextFrameVirenderSelected-2-OversetText.PNG

The result could be like that:

TextFrameVirenderSelected-2-OversetText-2.PNG

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Translate
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
Engaged ,
Aug 17, 2022 Aug 17, 2022
LATEST

Hi Uwe, many thanks for replying.

Regards

Virender

Translate
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