Copy link to clipboard
Copied
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:
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
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now