5 Replies Latest reply on Sep 20, 2012 1:08 AM by Bill joy

    JS :Object is Invalid

    Bill joy Level 1

      Hi all

      I want to insert footnote at the end of text.

      When i run my java script give error object is invalid at line no 7.


      #target indesign

      var myDocument = app.documents.add();

      var myTextFrame = myDocument.pages.item(0).textFrames.add();

      myTextFrame.geometricBounds = ["6p", "25p", "30p", "30p"];

      myTextFrame.contents = "Indesign";

      var word  =myTextFrame.parentStory.words.item(1);

      var insertionPoint=word.insertionPoints.item(-1);    // give error  at this line Object is invalid

      var footnote=insertionPoint.footnotes.item(1).add(at(1701733408));






        • 1. Re: JS :Object is Invalid
          Jump_Over Level 5



          Notice, that your frame words count = 1 (words[0]):


          myTextFrame.contents = "Indesign";

          var word  =myTextFrame.parentStory.words.item(0);  // there is only one word so words.item[1] is invalid



          • 2. Re: JS :Object is Invalid
            Bill joy Level 1

            Thanks Jump_Over for reply

            There is another problem in my Script in the selection of Image place in textframe. I am not understand this problem also. It give error  Undefined is not an object   in 5th line.


            myTextFrame = myDocument.pages.item(1).textFrames.add();

            myTextFrame.geometricBounds = ["20p", "25p", "30p", "35p"];


            var graphic=myTextFrame.allGraphics.firstItem;

            graphic.select("SelectionOptions.REPLACE_WITH");  // give error Undefined is not an object

            graphic.geometricBounds = ["20p", "25p", "30p", "35p"];



            if I use this line

            var graphic=myTextFrame.allGraphics.item(1).select("SelectionOptions.REPLACE_WITH");

            then it give error

            myTextFrame.allGraphics.item is not a function



            • 3. Re: JS :Object is Invalid
              Harbs. Level 6

              allGraphics is an array, not a collection.


              Use var graphic=myTextFrame.allGraphics[0];



              var graphic=myTextFrame.graphics.item(0);



              var graphic=myTextFrame.graphics.firstItem;

              • 4. Re: JS :Object is Invalid
                Jump_Over Level 5



                var graphic=myTextFrame.allGraphics.firstItem;   // supposed to be firstItem(), if isValid but...


                allGraphics is an array, not a collection, so there is no valid firstItem() method.

                use graphic[0] to refer to first element of array.


                By the way, still watch your (1) vs (0) indexes ==> first is (0)



                1 person found this helpful
                • 5. Re: JS :Object is Invalid
                  Bill joy Level 1

                  Thaks Harbs for reply


                  var graphic=myTextFrame.allGraphics[0];

                  work sucessfully.