InDesign JavaScript: MenuActions "action is not enabled" error
Hello,
I am writing a script to automatically perform a data merge on a template that contains a table of content that needs to be updated.
I have written the following function for updating the TOC, which works fine:
function updateTOCs(doc) {
var TOC = doc.textFrames.itemByName("TOC");
if(TOC == "[object TextFrame]"){
TOC.select();
app.menuActions.item("$ID/UpdateTableOfContentsCmd").invoke();}
else($.writeln("There is no text frame called TOC"));
}However, it doesn't work when I iterate through the merged documents like so:
for (var i = mergeDocs.length - 1; i >= 0; i--){
var openDoc = app.documents[i];
updateTOCs(openDoc);
}This gives the error “Action is not enabled”.
The TOC.select() seems to work fine. The only thing I can think of that might be a problem is that the app.documents[i] is not set to be the active document, would this matter? If so, how would I go about this? Or any idea what the problem could be otherwise?
Cheers,
Heidi
