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

Is there a way to filter a TOC?

New Here ,
Aug 01, 2023 Aug 01, 2023

Hey all!

 

Quick question... is there a way to 'filter' a TOC?

I have a list of figures set up at the back of my current project that is listing all figures throughout the document. This has been set up using paragrah styles.

 

Currently, I'm using a custom TOC formated to show the list of figures divided by what heading they fall under. The trouble is the TOC is also listing chapters of the document that don't contain any figures. Is there a funtion that will allow me to filter any headings without figures from showing? ie, have the TOC only show chapter headings that have figures?

 

This is how my TOC currently looks. I don't want any headings with the 'x' from showing as these chapters contain no figures:

1.JPG

 

This is the current setup of the TOC:

2.JPG

 

Cheers,

TOPICS
How to
724
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
LEGEND ,
Aug 02, 2023 Aug 02, 2023

As the TOC is generated automatically - there is no direct way to filter what will be created.

 

I think the only way would be if you use a different ParaStyle for the Chapter's title that doesn't have any Figures.

 

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 ,
Aug 02, 2023 Aug 02, 2023

Create another toc based on different styles. 

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
LEGEND ,
Aug 02, 2023 Aug 02, 2023

And how this will help? 

 

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
Guide ,
Aug 02, 2023 Aug 02, 2023

"As the TOC is generated automatically …" is totally false: an InDesign TOC is generated by a click (menu or K-shortcut).

 

So the good question would be: What click do you prefer?

 

Para Styles used for the TOC SettingsPara Styles used for the TOC Settings

Capture d’écran 2023-08-02 à 11.12.20.png


1 click:

 

 

/*
    _FRIdNGE-0740_UpdateTOC.jsx
    Script written by Michel Allio [02/08/2023]
*/

var myDoc = app.activeDocument;
var myStories = myDoc.stories,  S = myStories.length,  s;
for ( s = 0; s < S; s++ ) {
    if ( myStories[s].storyType == StoryTypes.TOC_STORY ) {
        myStories[s].textContainers[0].select();
        app.menuActions.itemByID(71442).invoke();
        // Grep 1
        app.findGrepPreferences = app.changeGrepPreferences = null;
        app.findGrepPreferences.findWhat = "^.+\\r(?=.)";
        app.findGrepPreferences.appliedParagraphStyle = "Chapter_Toc";
        app.changeGrepPreferences.changeTo = "";
        myDoc.changeGrep( );
        // Grep 2
        app.findGrepPreferences = app.changeGrepPreferences = null;
        app.findGrepPreferences.findWhat = "^.+\\z";
        app.findGrepPreferences.appliedParagraphStyle = "Chapter_Toc";
        app.changeGrepPreferences.changeTo = "";
        myDoc.changeGrep( );
        app.findGrepPreferences = app.changeGrepPreferences = null;
        app.selection = null;
    }
}
alert ( "TOC Updated! …" )

 

 

Result:

 

Capture d’écran 2023-08-02 à 11.18.26.png

(^/)  The Jedi

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
LEGEND ,
Aug 02, 2023 Aug 02, 2023

"Automatically" by InDesign based on the selected Styles. 

 

And OP will have to remember to run your script every time there are some changes in the document... 

 

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
Guide ,
Aug 02, 2023 Aug 02, 2023

… As (s)he will have to remeber to "update the TOC"!  😉

 

(^/)

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 ,
Aug 02, 2023 Aug 02, 2023

Thank you!

 

I'm keen to give this a try at work tomorrow. One small issue... How do I use the script? 😆

 

Also, would this script work with a book?

 

Cheers

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 ,
Aug 02, 2023 Aug 02, 2023

Using different styles for the headings you want to include and exclude is much simpler and more 'organic,' IMVHO. You can set everything up so that normal TOC generation — which, yes, I'd classify as 'automatic' — will create a clean, new TOC including just the headings you want, while leaving the variant headings apparently identical for all other purposes.

 

Not every task requires an effing script.

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
LEGEND ,
Aug 02, 2023 Aug 02, 2023

Exactly my point - "set and forget". 

 

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
Guide ,
Aug 02, 2023 Aug 02, 2023
LATEST

It works with a book of course.

 

For more, contact me in private!

 

(^/)

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 ,
Aug 02, 2023 Aug 02, 2023

Two things continue to catch and trip up the new user of the ToC generator:

1. More Options should be clicked to open it up

and

2. ToC presets are still called styles, which confuses the user in a dialog box where you choose *styles* to apply another *style* which might also make some auto-generated *styles* and save the whole thing as a ToC *style* but which is actually a named preset. 

This continues to be confusing to new learners and experienced users alike.

Mike Witherell
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 ,
Aug 02, 2023 Aug 02, 2023
quote

2. ToC presets are still called styles, which confuses the user in a dialog box where you choose *styles* to apply another *style* which might also make some auto-generated *styles* and save the whole thing as a ToC *style* but which is actually a named preset. 

 

This, in spades and with flashing neon pointers. TOCs are an entire schema in themselves, one dependent on careful assignment of several actual styles, and viewing each setup as a "style" is a self-defeating situation.

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 ,
Aug 02, 2023 Aug 02, 2023

Sort of, by sorting out styles and filtering them yourself.

 

  • Get your Selection/Arrow tool, with no text selected.
  • Go to your Paragraph Styles panel and select the style you use for your table header. Click once on it to highlight the style.
  • Go to the Flyaway Menu at the upper right of the panel and select the Duplicate Style... flyaway menu command.
  • When the Duplicate Paragraph Style dialog box appears, name it [Whatever your style name is] - No ToC.
  • Unless you choose to change something, all other style attributes will be unaffected. Click the OK button.
  • Now, tag all your ToC offenders with your No ToC style.

 

When you run your next ToC for the document(s), the No ToC style won't make the trip. Easy Peasy.

 

Hope this helps,

 

Randy

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
LEGEND ,
Aug 02, 2023 Aug 02, 2023

Already mentioned... 

 

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 ,
Aug 02, 2023 Aug 02, 2023

But not with a step-by-step process to accomplish the task ... as it is above.

 

Sometimes just do that thang isn't a sufficient answer.

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