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

How to Target (or Select) the Text Frame with a specific TOC Style Name

Explorer ,
Jul 30, 2022 Jul 30, 2022

Copy link to clipboard

Copied

Helloo,


Need your scripting(javascript) expertise with this. I am working on an INDB file where the Cover file contains 2 TOC TextFrames. Each with different TOC Style Name. Let's say "TOC_A" and "TOC_B".

Using the Update TOC Script (which I found online), it can select both textframe using a loop. But what I'm aiming is to select only the Textframe where it contains "TOC_B".

Any ideas?

TOPICS
Scripting

Views

1.5K

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

Guru , Aug 01, 2022 Aug 01, 2022

Here are two scripts: mine and Mark’s (at the bottom).

You can do this by labeling your text frame(s).

In my script, you can change the label from ‘contents’ to ‘TOC_B’ to target only those text frames that have this label. All text frames you want to update should be labeled.

 

In Mark’s script, you can add a line or two of code to either skip certain labels (TOC_A) or process only certain labels (TOC_B).

Off the top of my head, (totally untested; I just cast a glance at the code) you can check the

...

Votes

Translate

Translate
Community Expert ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

Hi @Martin PH,

Please share the script that you are using and reference to its source, only then will we be able to suggest if it can be edited or we would need a new solution. Did you try contacting the original author of the script?

-Manan

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
Community Expert ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

Hmm, I'm not even sure how feasible it is to do. Typically we get the Update TOC menu item and invoke the menu command if it is active. But the TOC styles are just attached to the Document object, and unless you examine particular characteristics of text within the TOC, I don't think there's a way to only invoke the command with that style applied, like you can do with traditional styles. An alternative would be to name the target frames in the INDD doc and simply invoke the command on those frames. 

 

 

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
Community Expert ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

You do not need a script tp find instances of a Style. You can use Find//Change (Edit > Find/Change) to find formatting or a Style.

  1. Open all your Book documents.
  2. Go to Find/Change (Edit > Find/Change).
  3. In the Text Tab of the dialog that opens, click in the Find Format section.
  4. Select the Paragraph Style to find,
  5. Make sure you're Searching All Documents.
  6. Press Find Next.

InDesign should find the first use of your TOC_B Style immediately.

Hope this helps!

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
Community Expert ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

Not at my computer at the moment, but pretty sure you cannot find text or object with a given TOC Style through the find/change UI. This is the style applied through the TOC menu, not a paragraph, character or object style. Now if TOC B used a distinct paragraph style then you could potentially target it that way assuming the text with the pstyle is always present. 

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
Community Expert ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

A Style is a Style, no matter how it's applied.

Please see attached screenshot.

It works!

Screen Shot 2022-07-31 at 1.38.19 PM.png

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
Community Expert ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

A TOC Style is not a Paragraph Style. A TOC Style leverages paragraph styles and other styles to style a TOC. It is configured and named in the TOC configuration menu. It is not findable through Find/Change. You are finding a Paragraph Style that the TOC Style applies, which is what I suggested as a possible approach at the end of my last post. A script would need to work up to the containing frame and invoke the UpdateTOC command. 

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
Community Expert ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

I think Jeff was thinking of the paragraph/character styles that the TOC style can automatically apply and/or paragraph styles that the TOC is looking for.

 

 

David Creamer: Community Expert (ACI and ACE 1995-2023)

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
Community Expert ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

Yes!

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
Community Expert ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

OK! I guess I'm really comfused by the OPs question?

 

Why would you ever need to find a Pareagraph Style that's never been used? The only thing I can think of is that you set up a TOC and then deleted it.

 

Any thoughts?

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
Community Expert ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

I'm not a scripter, but if you only want to update one of your TOCs, couldn't you just do it manually? Or is this step part of a larger script?

 

David Creamer: Community Expert (ACI and ACE 1995-2023)

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
Community Expert ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

Hi David,

I'm not a scripter either, but I use the Scripts that come with InDesign and others amazing Scripts that I've downloaded all the time. I use scripts to do things that would take a lot of time that can be completed in seconds using a great Script.

A great example is Calendar Wizard. You can set up a calendar with holidays in seconds. Great script: http://calendarwizard.sourceforge.net  Can't imagine how long it would take to create a 12-month calendar with a variety of holidays. 

We don't know the purpose of the script the OP wants. But if it takes hours to figure out a script that saves five minutes, why bother?

 

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
Guru ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

Here are two scripts: mine and Mark’s (at the bottom).

You can do this by labeling your text frame(s).

In my script, you can change the label from ‘contents’ to ‘TOC_B’ to target only those text frames that have this label. All text frames you want to update should be labeled.

 

In Mark’s script, you can add a line or two of code to either skip certain labels (TOC_A) or process only certain labels (TOC_B).

Off the top of my head, (totally untested; I just cast a glance at the code) you can check the label before the script selects the text frame, like so:

2022-08-01_10-32-36.png

// skip it and continue to update all other frames: unlabeled/with a different label
if (t.label == "TOC_A") continue;

 or process only TOC_B

try
	{
		if (t.label == "TOC_B") {
			app.select(t);
			if( mna.enabled )
			{
				mna.invoke();
				msg = "TOC updated in " + nme;
			}
		}
	}
	catch(e){ msg = nme + ': ' + e }
}

Once again: it's totally untested!

— Kas

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
Community Expert ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

Hi @Martin PH ,

well, what you can find is if a given story's storyType is of the kind StoryTypes.TOC_STORY.

And you could address the first frame of a given story with textContainers[0] from its textContainers array.

If you then have an additional indicator, like a paragraph style that is only used with a given TOC Style, then you could identify the text frames that were created with TOC Style "TOC_B" for example.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

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
Guru ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

LATEST

Thanks for your useful tip, Uwe!
I didn't know this.

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