• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JS Update TOC - CS6

Participant ,
Jul 10, 2018 Jul 10, 2018

Copy link to clipboard

Copied

I am working with code to update a single TOC in a document. Do you have to select the text frame where the existing TOC resides before updating the TOC? Here’s the code and errors:

var curDoc = app.activeDocument;

tocStyle = curDoc.tocStyles.itemByName("Default");

curDoc.createTOC(tocStyle, true);

Errors:

Invalid value for parameter ‘using’ of method ‘createTOC’. Expected TOCStyle, but received nothing.

TOPICS
Scripting

Views

411

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Jul 10, 2018 Jul 10, 2018

Before creating toc you have to add atleast one style in table of contents style and then save that style.

If you are using defoult style you can use tocStyles[0].

var curDoc = app.activeDocument;

tocStyle = curDoc.tocStyles[0];

curDoc.createTOC( tocStyle , true);

Votes

Translate

Translate
Community Expert ,
Jul 10, 2018 Jul 10, 2018

Copy link to clipboard

Copied

".. received nothing" means exactly that. If you print out the value of tocStyle, it will say "undefined"; you do not have a TOCStyle named "Default". Try with "...tocStyles [0]" instead (the top item, regardless of how it's called).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 10, 2018 Jul 10, 2018

Copy link to clipboard

Copied

Before creating toc you have to add atleast one style in table of contents style and then save that style.

If you are using defoult style you can use tocStyles[0].

var curDoc = app.activeDocument;

tocStyle = curDoc.tocStyles[0];

curDoc.createTOC( tocStyle , true);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

LATEST

Both of your answers are correct. Thank you, Jongware and payalm68947498.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines