Skip to main content
Liphou
Inspiring
June 8, 2021
Answered

[JS] Toc Convertion

  • June 8, 2021
  • 5 replies
  • 864 views

Good morning all,
Is there a command to convert a text block containing a Table of Contents to pure text, there I still have the TDM update option?
Thank you

Liphou

 

Bonjour à tous,

Exit-il une commende pour convertire un bloc texte contenent une Table des matière en pur texte, là, j'ai toujours l'omption mise à jour de la TDM?

 

Merci

This topic has been closed for replies.
Correct answer Laubender

Sorry. I still do not get it.

What exactly do you mean by: "I have the conversion in cross reference" ?

 

Ok. Let's assume you want an exact duplicate of your TOC's text frames and let's assume you have an idea how you can access one of the frames of your TOC, you could run a code like the one below where I assume that a text frame is selected:

 

var originalStory = app.selection[0].parentStory;
var textContainers = originalStory.textContainers;
var dupFrames = [];

for( var n=0; n<textContainers.length; n++ )
{
	dupFrames[n] = textContainers[n].duplicate();
	
	if( n == 0 ){ continue };
	
	dupFrames[n-1].nextTextFrame = dupFrames[n];
};

var dupStory = dupFrames[0].parentStory;

 

Regards,
Uwe Laubender

( ACP )

5 replies

Community Expert
June 14, 2021

For all readers who wonder, this thread is tied to this one:

 

[JS] Toc makeAnchor
Liphou, Jun 07, 2021
https://community.adobe.com/t5/indesign/js-toc-makeanchor/td-p/12095999

 

Regards,
Uwe Laubender

( ACP )

Community Expert
June 14, 2021

Oh. I would not dare to to this.

You would also remove hyperlinkTextSources that are not related to the TOCs.

 

Regards,
Uwe Laubender

( ACP )

Liphou
LiphouAuthor
Inspiring
June 14, 2021

Yes, while the source is there, I cannot create a cross reference instead, here the TOC is in a separate file so I can delete all of them without too much problem.

 

Oui, tanque la source est là, je ne peux créer une réference coisé à la place, ici le TDM est dans un fichier a part donc je peux tous suprimé sans trop de problème.

 

Tanks

Liphou

Liphou
LiphouAuthor
Inspiring
June 14, 2021

J'ai rajouté cette ligne aussi :

app.activeDocument.hyperlinkTextSources.everyItem().remove()
LaubenderCommunity ExpertCorrect answer
Community Expert
June 8, 2021

Sorry. I still do not get it.

What exactly do you mean by: "I have the conversion in cross reference" ?

 

Ok. Let's assume you want an exact duplicate of your TOC's text frames and let's assume you have an idea how you can access one of the frames of your TOC, you could run a code like the one below where I assume that a text frame is selected:

 

var originalStory = app.selection[0].parentStory;
var textContainers = originalStory.textContainers;
var dupFrames = [];

for( var n=0; n<textContainers.length; n++ )
{
	dupFrames[n] = textContainers[n].duplicate();
	
	if( n == 0 ){ continue };
	
	dupFrames[n-1].nextTextFrame = dupFrames[n];
};

var dupStory = dupFrames[0].parentStory;

 

Regards,
Uwe Laubender

( ACP )

Liphou
LiphouAuthor
Inspiring
June 8, 2021

Thank you Laubender,
It works very well.

We have so much to make adaptations to the table of contents, that each update, we have to redo them, a lot of wasted time.
And finally, I'm going to make a script that creates cross-references on just the folio of the table of contents and of course in a book 😉

Thank you very much a step taken

good to you

Liphou

 

-------------------- Traduction

 

Merci Laubender,
Cela fonctionne très bien.

Nous devons tellement à faire d'adaptations à la table des matière, que chaque mise à jours, on dois les refaire, beaucoup de temps perdu.
Et final, je vais faire un script qui cree des réference croisé sur juste sur les folio de la table des matières et biensur dans un livre 😉

Merci beaucoup un etape franchie

bien à toi

Liphou

Liphou
LiphouAuthor
Inspiring
June 8, 2021

je fais un petit controle en plus :

 

if (app.selection[0].parentStory.storyType == StoryTypes.TOC_STORY) {

        var originalStory = app.selection[0].parentStory;
        var textContainers = originalStory.textContainers;
        var dupFrames = [];

        for ( var n = 0; n < textContainers.length; n++ )
        {
            dupFrames[n] = textContainers[n].duplicate();
            
            if ( n == 0 ){ continue };
            
            dupFrames[n-1].nextTextFrame = dupFrames[n];
        };

        var dupStory = dupFrames[0].parentStory;
        app.activeDocument.hyperlinks.everyItem().remove();
}

 

Community Expert
June 8, 2021

Hi Liphou,

I'm a little confused. Do you mean you need a duplicate of a TOC story that you could update?

 

Or do you need a duplicate of a TOC that could not be updated?

In this case simply duplicate the frames holding the TOC and thread them in the right order.

Or duplicate the text of a TOC Story to a new text frame you added to the document.

 

Regards,
Uwe Laubender

( ACP )

Liphou
LiphouAuthor
Inspiring
June 8, 2021

Thank you Laubender,
I have the conversion in cross reference but as long as it is a table of contents it is not possible.
The table of contents is on several pages.
Bat
Liphou

 

Merci Laubender,

Je dois la convertire en referece croisé mais tant qu'elle est une table des matière c'est pas possible.

La table des matière est sur plusier pages.

Bàt

Liphou