I am working on a complex script to search and replace certain terms. In essence, it searches for the offensive term, shows it on the screen in the file and gives you a dialog box with a suggested edit. Everything works great, but when I'm processing a book, it doesn't pull up the found text range and display it on screen. If you run the script on just a single file, it works great and you can see the offensive term in context. But if you run it on the book and progress your way through the chapters, the file displayed on screen never changes. I know it's running because the display line at the bottom of the book window lists the file it's checking. It just would be nice for users to see the context of the offensive term.
I've tried calling ScrollToText and Redisplay just after finding the term and neither have any effect. I'm guessing that the focus is on the book and that prohibits the focus to switch to the file?
Any ideas or suggestions of things to try would be very much appreciated. I have scoured the scripting guide, and it's too obscure for a generic Google search to find anything.
If oDoc is the document your script is processing, use
app.ActiveDoc = oDoc
to bring that document into view, then use ScrollToText etc.
In addition to Jang's suggestion, you may need to make sure that the document is visible. Your book code may be opening the document invisibly. To do this, add this line before Jang's:
oDoc.IsOnScreen = 1;
In addition to the suggestions from Jang and Rick, another way to really force a doc to the front is to "open" it again. A simple call like:
Would the SimpleOpen not revert to the last saved document ? That could cause unwanted side-effects. The scripting reference does not mention what the behavior is in these cases. Maybe the FDK ref does.
Negative, SimpleOpen() will open whatever doc you specify. If the document is already open, it forces it to the front. I have found it to be a "stronger" call than setting ActiveDoc, IsInFront, etc.
Thanks. Good to know. I never noticed this function before. But then, most of the files I need to open are XML, DITA, SGML or some other species other than native FM - You know I like to work off the paved tracks, way out in the wilderness 😉
Jang, reading your post again, I see what you were saying. You were talking about the risk of a "Revert to Saved" action instead of a "bring to front" action. I don't think this is addressed in the documentation anywhere, but I have used the Open action reliably on unsaved documents since I started doing this stuff. The behavior has always been the same, in that if the doc is already open, it just comes to the front. Much like double-clicking it in a file explorer.
Many thanks to all of you for your suggestions. These seem like reasonable things to try. We'll have a go at them today, and tomorrow and I'll report back.
Thanks again for the ideas!