Skip navigation
Currently Being Moderated

Trouble updating TOC with Javascript

Feb 8, 2012 7:44 PM

Tags: #indesign_cs5.5 #scripting #extendscript

Using: Indesign 5.5 - javascript

 

 

I'm trying to simply force a toc that's already placed on a master page to update.

 

Upon searching it looks like using the createTOC() method should help accomplish this, but the ESTK gets stuck at the createTOC() line, saying simply "createTOC".

 

Here's what I'm using so far:

 

 

 

var myTOCstyle = document.tocStyles.itemByName("townTOC");

 

document.createTOC(myTOCstyle, true);

 

 

 

Does anyone have any suggestions?

 

Thanks much.

~Nate

 
Replies
  • Currently Being Moderated
    Feb 9, 2012 12:31 AM   in reply to rafikibubu

    @Nate – As always in cases like this when no method seems to match a thing you can do in the UI, I'm looking for a way to accomplish it through script menu actions.

     

    There might be a better method, but one always could try to invoke the appropriate script menu action:

     

    //SELECT the text frame that is holding your table of contents (TOC):
     
    myTOCtextFrame.select(); //You have to define "myTOCtextFrame" first!
    //Update Table of Contents by script menu action:
    try{
    app.scriptMenuActions.itemByID(71442).invoke();
    }catch(e){alert(e.msg)};
     
     
    //Deselect selection of text frame holding your TOC: 
    app.select(null);
     
    

     

    Uwe

     

    Message was edited by: Laubender

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 9, 2012 7:29 AM   in reply to rafikibubu

    @Nate – How does one look up a special menu action?

     

    For example see Jongware's method:

     

    http://forums.adobe.com/message/2858247#2858247

     

    In this case it's the "name" property. You can also look for "id" and get a handy table of names and IDs together.

     

    If you search this forum you will see other methods for listing menu actions…

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2012 7:04 PM   in reply to rafikibubu

    I have had mixed success with attempting the same thing and honestly the problem you are having is one that has made me pull quite a bit of my hair out.

     

    I have a tip for you.

     

    Look into your TOC style called "townTOC".  Is "Include Book Documents" on or off? 

     

    In my case, it was on, because the document was at one point part of a book.  After taking it out of the book, I could not revert this to off without reloading the style from another file (or adding it back to a book).

     

    Anyway, it seems like, if: "Include Book Documents" is On AND the Document is NOT in a Book, then document.createTOC will fail.

     

    But wait, there is a weird fix too.  I presume possibly you are doing things like me and you have not attached a window to your document because things work faster if the document is not visible. This error only seems to happen when the document has no window attached. Try this code and bang your head against the wall if it works.

     

    try{

         document.createTOC(myTOCstyle, true);

    }catch(e){

         document.windows.add();

         document.createTOC(myTOCstyle, true);

         $.writeln("Seriously? Why does this work!");

    }

     

    So, for me, I first learned of the second method, and was unsatisfied but at least my code didn't crash.  Now I have fixed the style to not have book contents and it seems to work.  Obviously there are a lot of specific circumstances at play so it would be very valuable if you could report back how this fits your situation and if any of this is helpful.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points