Copy link to clipboard
Copied
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 = "";
}
And without a for-loop (but why?):
app.activeDocument.textFrames.item('virender')
.paragraphs
.itemByRange (1, -1)
.remove();
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
And without a for-loop (but why?):
app.activeDocument.textFrames.item('virender')
.paragraphs
.itemByRange (1, -1)
.remove();
Copy link to clipboard
Copied
Hi Peter,
did not see your latest reply with the itemByRange() code.
Best,
Uwe Laubender
( Adobe Community Professional )
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Hi @virender_CTS ,
let's assume you want to remove all paragraphs in red of this situation:
So that the result is this:
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:
The result could be like that:
Regards,
Uwe Laubender
( Adobe Community Professional )
Copy link to clipboard
Copied
Hi Uwe, many thanks for replying.
Regards
Virender