I would like a script to update all tables of content in my document. I tried
var t = app.activeDocument.tocStyles;
for (var i=0; i<t.length; i++) {
app.activeDocument.createTOC(t[i],true);
}
as suggested here, but for those TOC styles I do not uses it creates a new story. So, how can I figure out whether a TOC style is actually used? I know I can loop over all stories and check whether their storyType
is StoryTypes.TOC_STORY
, but I haven't figured out how to determine which TOC style that story then uses or how to refresh specifically that story. I even considered using
app.menuActions.item("$ID/UpdateTableOfContentsCmd").invoke();
which would just use the menu action (which sounds like something to avoid), but in that case I fail due to the action being inactive - I must change the selection somehow first, but app.select(story)
fails due to an invalid data type...