: How to refresh all TOCs via a script? 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++)
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...
More posts by @YK2262411
1 Comments
Sorted by latest first Latest Oldest Best
Ok, here's my "solution" so far, unfortunately relying on using menuActions:
function updateTOCs() {
var stories = app.activeDocument.stories;
for(var i=0; i < stories.length; i++) {
var story = stories[i]
if(story.storyType != StoryTypes.TOC_STORY)
continue;
story.textContainers[0].select()
app.menuActions.item("$ID/UpdateTableOfContentsCmd").invoke();
}
}
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.