7 Replies Latest reply: May 2, 2012 7:40 AM by pkrk RSS

    parentPage

    pkrk

      If allTextFrames is a collection of text frames from a layer, why does the line below give me a null error?

       

      currentPage= allTextFrames[i].parentPage;

       

       

       

      I’m currently working around it by doing this line below so I can export PDFs via page range with the value in currentPage.

       

      currentPage= allTextFrames[i].parent.index+1;

        • 1. Re: parentPage
          John Hawkinson Community Member

          Can you please show us how you construct allTextFrames?

          I can run this without error:

           

          >> t=app.activeDocument.textFrames.everyItem().getElements();

          [object TextFrame]

           

          >> t[0].parentPage

          [object Page]

           

           

          What is "a null error"?

          • 2. Re: parentPage
            pkrk Community Member

            var allTextFrames = new Array();

            allTextFrames = myLayer.textFrames;

             

             

            for( i=0;i<allTextFrames.length;i++)

            {

            currentPage= allTextFrames[i].parent.index+1;

            alert(currentPage);

            }

             

            The alert shows me nulls.

             

            I get a a "type error null is not an object" but I now realize that is later in the script.

            • 3. Re: parentPage
              John Hawkinson Community Member

              I assume you mean .parentPage in the assignment line of your script.

              In which case the alert shows me "[Page]" which is as it should be.

              What version of InDesign?

               

              Also, this construction:

              var allTextFrames = new Array(); 
              allTextFrames = myLayer.textFrames;
              

               

              is both superfluous and unwise. You declare allTextFrames, initially assign it the value of the Array constructor, as if it were an array, and then you assign it to a collection.

              A collection is not an array. So now you use the same variable to represent two different types. This is acceptable in JavaScript, but bad style, because it promotes confusion about what type things are.

               

              In this case, simply

               

              var allTextFrames = myLayer.textFrames;

               

              would be sufficient.

              What's the minimal document necessary to make your script fail?

              Also, it would be nice to see an example that stands on its own.

              This one depends on myLayer, so it's annoying for others to test.

              • 4. Re: parentPage
                pkrk Community Member

                Thank you.

                 

                CS 5.5

                 

                 

                I just tried it in 5 and parentPage works??????

                 

                 

                I wonder if there is any harm in referencing the pages by index instead like I did to get it to work in 5.5.

                • 5. Re: parentPage
                  John Hawkinson Community Member

                  It works fine for me in CS5.5, 7.5.2.318 on a Mac.

                  I think we'll need more details about your document and its layer construction.

                  What happens if you create a new document with a single textframe?

                  • 6. Re: parentPage
                    Marc Autret Community Member

                    A TextFrame is always located on a Spread but not necessarily on a Page. That's why tf.parentPage may be NULL.

                     

                    To see what exactly happens use the following test:

                     

                    alert( myLayer.textFrames.everyItem().parentPage.toSource() );
                    

                     

                    @+

                    Marc

                    • 7. Re: parentPage
                      pkrk Community Member

                      Looks like it is because some of the frames are on the pasteboard.

                       

                      The script is working with my implementation above.

                       

                      Thanks  for your help.