5 Replies Latest reply on Sep 21, 2012 3:56 PM by Jump_Over

    [JS] Found text is not a text?

    Jump_Over Level 5

      Hi,

      Could you help me to find a reason of 'undefined is not an object' error, pls?

       

      ....

      app.findTextPreferences = NothingEnum.nothing;

      app.findTextPreferences.appliedParagraphStyle = myParaStyle;

      mFound = myStory.findText();

      if (myFound.length > 0)

           mStart = myFound[0].insertionPoints[0];     // here is error 'undefined is not an object'

      ....

       

      this is a part of preety long code and I wouldn't paste it here, but:

      I checked some variables properties:

      mFound.length  = = 1 so InD found some text, I guess;

      mFound[0].constructor.name = = "Array";

      mFound[0].length = = 0;

       

      so what is found by ID (which .appliedParagraphStyle = = myParaStyle) and why this is not a text?

       

      If I run this part of code manually, starting from point where script ends ==> mFound.length = = 0.

      I know that I made mistake(s) somewhere, but I have not idea what should I look for...

      Has 0-element Array some property to check and discover, where it came from?

       

       

      Help me pls.

      Thx

        • 1. Re: [JS] Found text is not a text?
          Jump_Over Level 5

          continue...

           

          is that true, that if text area for Find() is an array element, i.e.:

           

          myStory = SomeStory.texts[0]

           

          then mFound[0].length always is 1, and

          if something is found ==> mFound[0][0].length > 0 has to be checked?

           

          ... and why?

          • 2. Re: [JS] Found text is not a text?
            Marc Autret Level 4

            Hi Jump_Over,

             

            Your sample code both uses mFound and myFound. Just a typo?

             

            @+

            Marc

            • 3. Re: [JS] Found text is not a text?
              Jump_Over Level 5

              Hi Marc,

               

              Thanks for your observation and sorry for my carelessness, but yes - there is a typo.

              Found result variable length ==1. It 1st element length == 0 and it is not a text

              • 4. Re: [JS] Found text is not a text?
                Marc Autret Level 4

                Now to your question:

                 

                1) Usually, myArea.findText() will return an Array of zero, one or more Text objects. In other words, provided that myFound.length > 0, each myFound[i] should be a Text specifier. This is what happens if myArea is the Application, a Document, a Story, or any singular Text specifier.

                 

                2) BUT, if for some reason myArea is a plural specifier—such as myStory.paragraphs.everyItem()—then myArea.findText() will return an Array of Array(s) of Text(s). The outer array reflects the plural behavior of the specifier, while the inner arrays reflect the return type of the findText() method. In that case you may have empty arrays within the outer array. Indeed:

                 

                   myStory.paragraphs.everyItem().findText()

                 

                will send the findText() command to every paragraph, so any paragraph that does not match the query will produce an empty array.

                 

                Maybe your script leads to something similar. We'd need to see more code to figure it out.

                 

                @+

                Marc

                • 5. Re: [JS] Found text is not a text?
                  Jump_Over Level 5

                  Thanks Marc for your explanation!

                  It is that, indeed!