2 Replies Latest reply on Dec 13, 2008 8:41 AM by (gfellenz)

    [IDCS3] [JS] Access/Retrieve part of a Story by Index

    Level 1
      hi all,

      i want to add some sort of logging to find/change operations. the idea was to write a csv-log like:

      findWhat,changeTo,surrounding text before,surrounding text after

      this would be especially useful for checking grep find/change operations, because they can produce accidental replacements.

      so far i've no idea how to access an story object by index. my idea is to select the text based on the insertionPoints i retrieve from the find/change results:

      app.findGrepPreferences.findWhat = "\\t(\\d+)";
      var _findErg = app.activeDocument.findGrep ();

      for (var i = _findErg.length - 1; i >= 0; i--) {
      var index = _findErg[0].index;
      app.select(_findErg[0].parentStory.insertionPoints[index - 15])
      app.select(_findErg[0].parentStory.insertionPoints[index + 15], SelectionOptions.ADD_TO)
      $.writeln (app.selection[0].contents);
      }

      this works fine (i know there will be some more checking for production use to avoid getting out of bounds etc, but this is a second point).

      i wonder if there is any more elegant/efficient method to access the textrange?

      i've no idea how to achieve this with a story or text object, thought of sth. like:

      app.texts.get(InsertionPoint,InsertionPoint)

      any ideas?

      thanks in advance,
      gregor