Saturday, January 14, 2006

 

Better View after Find

This morning, I finally bit the bullet and wrote a script to deal with one of InDesign's annoying little habits. After a Find, it will often display the found text in a remote corner of the screen, with most of what you're really interested in (the text around the found item) either off-screen to the left or below the window. So, I borrowed an idea from the selectIt() function I've written about before and came up with what I call: BetterViewAfterFind.jsx:
//DESCRIPTION: A Better View after Find

var myZoom = app.activeWindow.zoomPercentage;
app.activeWindow.zoom(ZoomOptions.showPasteboard);
app.activeWindow.zoomPercentage = myZoom;
There! That's better. The "showPasteboard" command might not be strictly necessary for this situation in that the Find command does make sure that the found item is in the window to start with.

Perhaps I should take this opportunity to rewrite the selectIt() function. You may recall that it looks like this:
function selectIt(theObj) {
 // Selects object, turns to page and zooms in on it
 app.select(theObj,SelectionOptions.replaceWith);
 app.activeWindow.zoom = ZoomOptions.fitPage;
 app.activeWindow.zoomPercentage = 200
}
I've never been particularly happy with that arbitrary 200%. I always reasoned that I could change the number for any particular use, but why not just use whatever zoom value the user has set? The objective is to get the item front and center. Also, if theObj is on the pasteboard, this particular logic will fail because the fitPage command will not bring the object into the window and consequently the zoom to 200% will merely zoom in on the center of the page, not the selected object.

But wait! Let's think this through a tad more. What this function really does is show the user the object. Selecting it is incidental (although selecting it does clarify for the user just what he's being shown). So, I'm going to change the name to showIt() and I'm going to change the functionality, making the argument optional. This way, if there is already a selection, then the function will show that rather than selecting the passed object:
function showIt(theObj) {
 if (arguments.length > 0) {
  // Select object, turn to page and center it in the window
  app.select(theObj);
 }
 // Note: if no object is passed and there is no selection the current page
 // will be centered in the window at whatever zoom is being used
 var myZoom = app.activeWindow.zoomPercentage;
 app.activeWindow.zoom(ZoomOptions.showPasteboard);
 app.activeWindow.zoomPercentage = myZoom;
}
And that means that my BetterViewAfterFind script can be rewritten to use this function:
//DESCRIPTION: A Better View after Find

showIt();
Of course, the real script follows the call with a copy of the function.

I'm thinking that a smarter version of showIt could be written that would provide functionality similar to that of clicking the Go To Link button in the Links palette. I think this could only work for non-text selections, but basically, the script could calculate the zoom value needed to "fill the window" with the selection. But I'll leave that for another day when I'm less busy.

Comments:
Hello Dave,

thanks for the selectIt(theObj)-function. I could use it in a script that should look for an object with a special fillcolor or strokecolor: http://www.hilfdirselbst.ch/foren/Objekt_mit_bestimmter_Farbe_suchen_P205516.html#205516

Martin
 
This comment has been removed by a blog administrator.
 
Just one remark:

"app.activeWindow.zoom = ZoomOptions.fitPage;" should be "app.activeWindow.zoom(ZoomOptions.fitPage);"

Thanks
Martin
 
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?