Skip to main content
ali u
Inspiring
February 14, 2023
Answered

Script to insert a paragraph after every table

  • February 14, 2023
  • 2 replies
  • 697 views

I want to add a paragraph after every table in my document, i was able to insert it before tables with this script but couldn't figure out how to insert it after tables, any help?

 

var tables = app.activeDocument.stories.everyItem().tables.everyItem().storyOffset
for (var i = 0; i < tables.length; i++) {
tables[i].contents = "\r";
}

This topic has been closed for replies.
Correct answer rob day

Hi @ali u , Also if you want to add a paragraph after try this:

 

var ip = app.activeDocument.stories.everyItem().tables.everyItem().storyOffset;
var nl;
for (var i = 0; i < ip.length; i++) {
    nl = ip[i].index + 1
    ip[i].parent.insertionPoints[nl].contents = "\r";
}

2 replies

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
February 14, 2023

Hi @ali u , Also if you want to add a paragraph after try this:

 

var ip = app.activeDocument.stories.everyItem().tables.everyItem().storyOffset;
var nl;
for (var i = 0; i < ip.length; i++) {
    nl = ip[i].index + 1
    ip[i].parent.insertionPoints[nl].contents = "\r";
}
ali u
ali uAuthor
Inspiring
February 15, 2023

Thank you very much!

brian_p_dts
Community Expert
Community Expert
February 14, 2023

I would apply a paragraph style with correct Space Before and Space After settings to the story offset insertion point. 

app.activeDocument.stories.everyItem().tables.everyItem().storyOffset
for (var i = 0; i < tables.length; i++) {
tables[i].applyParagraphStyle("nameofsryle");
}