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

Get unused text styles using Extendscript

Participant ,
Dec 28, 2022 Dec 28, 2022

I use Extendscript to help me review students' work in InDesign. I run a script (.jsx) that goes through a document and creates a report. The point is to avoid manual, tedious and error-prone work for about 5 InDesign files x 60 students per semester. The report already includes many things like page size, bleed, margins, parent page columns and application, text style options, baseline grid, etc. This script saves me a HUGE amount of time and makes it less likely that I'll forget to check for anything in particular.

 

What I cannot do yet is to include in this report wether or nor unused paragraph and character styles exist, preferably listing their names.

 

I tried:

  • Searching the documentation for a property that might indicate if the paragraph/character style is being used or not.

  • Invoking (.invoke() method) the Select All Unused menu action from the Paragraph Styles panel. I explored adding event listeners and looking for any results, and also checked the Panel javascript documentation for any way to access a selection. According to what little I found, this is not possible because there's nothing relative to a selection regarding UI elements.

 

I also considered looping through all stories and paragraphs, checking for the styles in use, and accounting for styles used inside other styles (like "based on"). I've yet to explore scripting with find/replace, because that option would not tell me wether a style with zero uses is the basis for another style. Also, I feel there should be a simpler alternative. Does anyone know of one?

TOPICS
Scripting
2.8K
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
Mentor ,
Jan 04, 2023 Jan 04, 2023

@Robert at ID-Tasker – Yes, and yes.

We're looking for used styles (so that the unused ones remain) and I provided a list of candidates where we can ignore the methods.

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 ,
Jan 04, 2023 Jan 04, 2023

?? Then what is wrong with my idea? 

 

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 ,
Jan 04, 2023 Jan 04, 2023

Robert, your idea is great—nothing wrong with it as far as I can tell. When I have time I'm going to try it and Peter's idea and look into how difficult it would be to adapt my initial approach to collect all the little edge cases that Dirk mentions. I think Manan will be really interested too. I'm pretty sure that your idea and Peter's will be the easiest to implement. Anyhow, it'll be fun to explore. Just too busy right now...

- Mark

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 ,
Jan 04, 2023 Jan 04, 2023
LATEST

Yes, my and Peter's are almost exactly the same 😉 

 

I just don't understand what is the point of going through all the possible locations in the *Styles to check if style is used?

 

Unless the goal changed? 

 

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 ,
Dec 31, 2022 Dec 31, 2022

All you are saying about style's dependencies is rather obvious 😉 

 

That's why I've suggested copying pages to a new document - all this headache will be InDesign's problem 😉 scripter will have to just compare the lists 😉 

 

And checking if right style have been used - first, you have to check WHERE it has been used, not just IF. 

 

About your last part - and re-importing styles - it should be done through template - not by importing file from last month 😞

 

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 ,
Dec 31, 2022 Dec 31, 2022

That's why I've suggested copying pages to a new document

 

Robert's idea of copying all text to a second document is clever, but there's no need to copy pages. All you need to do is duplicate all the document's page items to a new document and that document will then contain only the used styles:

app.documents[0].pageItems.everyItem().duplicate (
  app.documents[1].pages[0]
);

 Everything will be on the first page on top of each other, but that doesn't matter. Then you can compare the two documents and obtain the unused styles.

Naturally, all the caveats that Dirk mentioned still apply.

P.

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 ,
Dec 31, 2022 Dec 31, 2022

Yeah 😉 but would be great to check on some large / complicated document if copying whole pages wouldn't be quicker 😉

 

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