In my dream world, all received texts for books etc. is marked up using styles from e.g MS Word. In my real world, that is unfortunately rarely the case.
I have written this script to help in the situations where a long text is formatted quite consistently, different headings are perhaps marked with bold and in a bigger font size, quotations are italic etc.
Walkthrough
I have imported a text file in InDesign, but it is not marked up with styles correctly, and there would be no reason to reuse the current styles. So I will just delete all the imported styles, but preserve the formatting, so the style panels are all clean.
Placing the cursor in the text flow somewhere will let the script know what story I want it to work with. Now, activating the script, it will automatically run through all paragraphs in the story, check how they differ from the Basic Paragraph style, and create new one's where needed.
Each time it has created a new style, it will also check if that style will apply to the paragraph it is checking, ensuring that all the paragraphs with the same text formatting will end up having the same paragraph style.
Furthermore it will also check all text for any local formatting within the paragraphs, so bold text will get a character style, italic text, coloured text etc. Also these will be reused, so where its applicable the same style will be used.
Where you go from the result of a lot of AutoStyles is up to you. I prefer to create new styles, then delete the AutoStyles one by one from the panel, replacing them with the new styles.
The script will unfortunately not do all the hard work for you, but is a great tool in cleaning up messy documents!
The script
The JavaScript can be downloaded here: auto_create_p_c_styles.jsx.
You can add it to your Scripts palette and run it from there. To do that, place the file inside the "~/Library/Preferences/Adobe InDesign/Version 6.0/Scripts/Scripts Panel" folder.
Note that depending on the length of your document, the script might take a while to run.
Known bugs:
- If the first word of a paragraph is "locally formatted", the script will think that is the "general formatting" of the whole paragraph.