1 Reply Latest reply on Nov 24, 2008 5:55 PM by (Simon_Paterson)

    get next character in a story with xml Tags

    srakete Level 1
      I have a character selected, and I want to have the next character in my story which is not
      an XmlTag element. InDesign counts these as a character. I have done this:

      Character.prototype.getNextCharacter = function() {

      var myStory = this.parentStory;
      var myCharacters = myStory.characters;
      var myNextCharacter = myCharacters.nextItem(this);

      while (myNextCharacter.contents == "\ufeff") { // Unicode for XmlTag
      myNextCharacter = myCharacters.nextItem(myNextCharacter);
      return myNextCharacter;

      var mySel = app.selection[0];
      var myNextCharacter = mySel.getNextCharacter();

      But it is terribly slow! I have 10 tags following my character and it takes 2 seconds to finish. Has anyone a better idea ?

        • 1. Re: get next character in a story with xml Tags
          Dave Saunders pointed out in one of his blog posts that nextItem was slow, and I've since noticed the same thing.

          Perhaps you can get the contents of the characters from the insertion point onwards and then iterate through them. That may actually be quicker. Or perhaps do a find operation on the text from the insertion point to the end of the story and take the first one from the returned array. I think either of these methods will be quicker than using nextItem.