I'm working on a script to automatically assign paragraph and character styles to texts that are sent to me by other writers. I do grep find/replace to apply the right styles to the right paragraphs. The problem is that it seems like the function changeGrep() clears overrides when it appiles the paragraph style. Is there any way to disable that behaviour? If I do a manual grep find/replace in inDesign with the same settings the overrides are not cleared so it should be possible.
This is an example of my code:
app.findGrepPreferences = NothingEnum.nothing; app.changeGrepPreferences = NothingEnum.nothing; app.findGrepPreferences.findWhat = "^\\d+\\w"; app.findGrepPreferences.pointSize = 12; app.findGrepPreferences.fontStyle = "Regular"; app.findGrepPreferences.dropCapLines = 2; var styles = app.activeDocument.paragraphStyles; var style; style = styles.item("p-new-chapter"); app.changeGrepPreferences.appliedParagraphStyle = style; myStory.changeGrep();
To keep overrides, you need to use a different method:
found = app.activeDocument.findGrep();
for (i = 0; i < found.length; i++)
found[i].applyParagraphStyle (myStyle, false);
where 'false' stands for 'do not clear overrides'.
Great! This not only solves my problem but will help me in other situations as well. I was actually wondering if there was a way to just find the instances matching the search and apply the changes differently depending on the circumstances. I belive findGrep() should let me do that!