Hi,
Does anyone know how to reset the findTextPreferences.appliedParagraphStyle value?
A script I'm working on uses InDesign's findTextPreferences to search for a paragraph style, e.g.:
app.findTextPreferences.appliedParagraphStyle = myDoc.allParagraphStyles[3]; // just an example
Once the script finishes, I would like to reset the findTextPreferences back to what it was, so the user doesn't have the hassle of doing it.
However, storing the paragraphStyle in a variable doesn't work, e.g.:
myOldParaStyle = app.findTextPreferences.appliedParagraphStyle;
because myOldParaStyle now contains a non-unique String object! (Tested in CS6). I never realised this before.
For instance, say in your document you have a paragraph style called "SubheadA", and you have a paragraphStyleGroup called "Footnotes" and inside that group you also have a paragraph style called "SubheadA" -- i.e. you have two identically names paragraph styles in your document, the only difference being that one is in a group called "Footnotes."
In both cases, myOldParaStyle will contain the String "SubheadA" -- so there's no way of knowing which paragraph style was actually selected.
In a more regular case (where there are not 2 similarly-names paragraph styles in the document), you still can't know exacltly where myOldParaStyle is, because if it is in some nested paragraphStyleGroup you're going to have to loop through them all to find one called that.
In brief: Does anyone know a fail-safe way of restoring the user's appliedParagraphStyle in the Find dialog, after a script changes those settings?
Alternatively: Does anyone know a way of scripting findText() without actually affecting the Find/Change UI dialog?
Many thanks,
Ariel
PS I would add that the following "almost" works, except for a handful of properties (including, unfortunately, the paragraph style):
myOldProperties = app.findTextPreferences.properties;
// do some findText() stuff with modified properties...
// Now restore them:
app.findTextPreferences.properties = myOldProperties;
This is really quick and easy, and seems to work for 95% of properties -- almost a perfect solution! But when it comes to a few basics, like findTextPreferences.appliedParagraphStyle it lets us down. And there doesn't seem to be a way to do it manually either!