Подскажите, почему не работает поиск назад. Результатом поиска является последний -BLA-, и почему при повторном запуске ничего не происходит? Может, есть альтернативные варианты?
Источник: find next and find previous with indesign javascript
Источник: find next and find previous with indesign javascript
Код:
var main = function() {
var doc = app.properties.activeDocument,
selText, st, ftp = app.findTextPreferences.properties, found, n, currIndex, foundIndex, nextText;
if ( !doc ) return;
if (
app.selection.length!=1
|| typeof ( app.selection[0].properties.baselineShift)=="undefined"
|| (app.selection[0] instanceof TextFrame )
) {
alert("Please select text then run the script again" );
return;
}
app.findTextPreferences = null;
selText = app.selection[0];
st = selText.parentStory;
app.findTextPreferences.properties = {
findWhat : "BLA"
};
found = st.findText();
n = found.length;
if ( !n ) {
alert("No results found, sorry." );
return;
}
currIndex = app.selection[0].index;
while ( n-- ) {
foundIndex = found[n].index;
if ( !nextText && foundIndex<currIndex ) {
nextText = found[n];
}
else if (foundIndex<currIndex && foundIndex>nextText.index) {
nextText = found[n];
}
else {
break;
}
}
app.findTextPreferences.properties = ftp;
if ( !nextText ) {
alert("No further results, sorry." );
return;
}
if ( nextText.parentTextFrames.length && nextText.parentTextFrames[0].parentPage ) {
var c1 = nextText.characters[0].words[0].characters[0],
cn = nextText.characters[-1].words[0].characters[-1];
var data =
{
geometricBounds:[c1.baseline, c1.horizontalOffset/1.25, c1.baseline-c1.pointSize, cn.endHorizontalOffset*1.25],
};
var rect = nextText.parentTextFrames[0].parentPage.rectangles.add(data);
// zoomObject ( rect );
rect.remove();
}
app.select( nextText );
}
//Snippet designed by Dave Saunders at http://jsid.blogspot.fr/2006/01/zoom-in-on-object.html
function zoomObject(theObj) {
try {
var objBounds = theObj.geometricBounds;
} catch (e) {
throw "Object doesn't have bounds."
}
var ObjHeight = objBounds[2] - objBounds[0];
var ObjWidth = objBounds[3] - objBounds[1];
var myWindow = app.activeWindow;
var pageBounds = myWindow.activePage.bounds;
var PgeHeight = pageBounds[2] - pageBounds[0];
var PgeWidth = pageBounds[3] - pageBounds[1];
var hRatio = PgeHeight/ObjHeight;
var wRatio = PgeWidth/ObjWidth;
var zoomRatio = Math.min(hRatio, wRatio);
app.select(theObj); // to make active the page that holds theObj
myWindow.zoom(ZoomOptions.fitPage);
myWindow.zoomPercentage = myWindow.zoomPercentage * zoomRatio;
//exit() // Because there's no point in doing this if you don't exit to let the user see
}
var u;
app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "The Script" );
Последнее редактирование: