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

Insert TOC into specific text frame

New Here ,
Feb 24, 2019 Feb 24, 2019

Hi,

I'm trying to insert a TOC and then later update it on a specific page of my catalogue document. The document is being created programmatically using scripts. CreateTOC is a document level method and works well as in:

var myDocument = app.documents.firstItem();

var myTOC = myDocument.tocStyles.itemByName("DirectoryTOC");

myDocument.createTOC(myTOC);


That puts a TOC on the current page at position 0,0 in a new text frame. However I want the TOC to go specifically into the text frame already placed on page 4 of my document.

Because I am also paginating data into the document programmatically, I need to do the following:

  • Insert TOC page and add a TOC to it
  • Insert data into catalogue pages
  • Update TOC (this should insert extra pages at front of document to the TOC section depending on how much data was added to catalogue pages)
  • Update TOC again, because the page numbers for the catalogue data will now have shifted by the number of pages added into the TOC.
  • Then continue to add content at the end of the document.

So does anyone know how I can target a specific text frame for my new TOC, and then once done, what would I use to update said TOC later on?

I tried also using the ID of the menu command to insert a TOC, but all that does is pop open the Create Toc dialog. Not helpful to me because the document is being created by scripts.

Cheers,
Rob

TOPICS
Scripting
1.2K
Translate
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

Community Expert , Feb 25, 2019 Feb 25, 2019

Hi Rob,

set property nextTextFrame of the text frame generated by createTOC() to the frame you like to flow the TOC in.

Then remove the frame that was created by createTOC().

Regards,
Uwe

Translate
Community Expert ,
Feb 25, 2019 Feb 25, 2019

Hi Rob,

set property nextTextFrame of the text frame generated by createTOC() to the frame you like to flow the TOC in.

Then remove the frame that was created by createTOC().

Regards,
Uwe

Translate
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
Community Expert ,
Feb 25, 2019 Feb 25, 2019

Hi Rob,

for updating an existing TOC set the second argument of method createTOC() to true.

var myDocument = app.documents[0];

var tocStyleName = "DirectoryTOC";

var myTOCStyle = myDocument.tocStyles.itemByName( tocStyleName );

if( myTOCStyle.isValid )

{

    myDocument.createTOC( myTOCStyle , true ); // Second argument: Update existing TOC

};

See DOM documentation by Jongware:

Adobe InDesign CS6 (8.0) Object Model JS: Document

With CC-2019 there is nothing new in this regard:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html#d1e49265__d1e53079

( CC 2019 DOM documentation compiled by Gregor Fellenz )

Regards,
Uwe

Translate
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
New Here ,
Feb 25, 2019 Feb 25, 2019

Thanks so much Uwe.

I didn't realise you can move the content that way from frame to frame and then delete the original frame. Worked perfectly. Well it did after a couple of scripting oddities. I got the ambiguous CreateTOC error which I'd already read was about my template being saved while on a master page and not a content page. And then I realised when I ran my full script the TOC frame was being put on page 0 instead of page 3 in my test system. Once I'd adjusted my code for that, all went well.

The TOC was inserted correctly, and after paginating all my categories for my directory, updated and reflow TOC pages were inserted at the beginning just where I wanted them.

Thanks again,
Rob

Translate
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
Community Expert ,
Feb 26, 2019 Feb 26, 2019
LATEST

Hi Rob,

the trick with nextFrame is to maintain the story that constitutes the TOC.

Removing a text frame of a story does not mean that the text in the frame is removed until you remove the last and only frame of a story.

FWIW: You could have moved texts[0] from the TOC story to the first insertion point of the story of your predefined text frame without removing the frame where the TOC initally was created. But then updating the TOC would mean moving the text again and before removing all the previous text of the predefined text frame. Also you had to move the TOC's text frame to the pasteboard.

Regards,
Uwe

Translate
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