Mobile app version of vmapp.org
Login or Join
YK2262411

: 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++)

@YK2262411

Posted in: #AdobeIndesign #IndesignScripting #TableOfContents

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...

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @YK2262411

1 Comments

Sorted by latest first Latest Oldest Best

 

@YK2262411

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();
}
}

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme