8 Replies Latest reply on Mar 1, 2016 4:07 AM by chrisnaylor

    Create TOC on active page

    franzi_ska

      Hello Scripters,


      I am trying to create my toc on the fifth page of my document.

      At the moment the script is running I am adding the fifth page and scripting like this:

       

      function toc() {
          var myTOCStyle = myDocument.tocStyles.itemByName("TOC_normal");
          var myTocPage = myDocument.pages.add(LocationOptions.AT_END);
          var myBounds = myGetBounds(myDocument, myTocPage);
          var myX1 = myBounds[1];
          var myY1 = myBounds[0];
          var myStory = myDocument.createTOC(myTOCStyle, true, undefined, [myX1, myY1]);
      }

       

      the script creates the toc on page 4 with bounds of page 5 (right page).

      doesn't the script always creates the toc at the active page? this should be page 5, as it was just added?


      I do not want to move the toc-frame after creating it, I want the script to place the toc on the correct page, what's wrong with my code?


      Thanks a lot in advance for any answer,


      franzi_ska

        • 1. Re: Create TOC on active page
          AdobeScripts Level 3

          franzi_ska wrote:

           

          function toc() {
              var myTOCStyle = myDocument.tocStyles.itemByName("TOC_normal");
              var myTocPage = myDocument.pages.add(LocationOptions.AT_END);
              var myBounds = myGetBounds(myDocument, myTocPage);
              var myX1 = myBounds[1];
              var myY1 = myBounds[0];
              var myStory = myDocument.createTOC(myTOCStyle, true, undefined, [myX1, myY1]);
          }

           

          how you read and return PageBounds in myGetBounds function ? how you have set RulerOrigin - to Spread or to Page ?

           

          try this (sorry, but I'm not JS man):

           

          app.activeWindow.activePage = myTocPage;

          var myX1 = myTocPage.bounds[1];
          var myY1 = myTocPage.bounds[0];

            

          robin

           

          www.adobescripts.co.uk

          • 2. Re: Create TOC on active page
            franzi_ska Level 1

            Hi Robin,


            thanks for your answer.

            I've set the RulerOrigin to Page. In all other cases it works (except for the TOC ).

            The myGetBounds function returns the correct Bounds (I see it because it's not correct for the left page, but for the right page).

            At the end I get the correct Bounds, but the wrong page.

            I also tried the extra active page line, unfortunately nothing changed.

            To me it is absolutely illogical.

            Any other suggestions?


            Thanks, Franzi_ska

            • 3. Re: Create TOC on active page
              AdobeScripts Level 3

              franzi_ska wrote:

               

              [...]

              Any other suggestions?

               

               

              why you can't use Move method after creating TOC ?

              you can specify page instead of position

               

              robin

               

              www.adobescripts.co.uk

              • 4. Re: Create TOC on active page
                franzi_ska Level 1

                I'd like to avoid moving the textframe after placing it, I would like the toc to automatically be placed at the correct page. Without knowing where the error lies, I think it's not the best idea to take the move Option. If handling other import data with other make-up in the document, the toc is then maybe placed correctly (and then unfortunately automatically placed onto the next page). So to me, the better option would be to find the reason for the problem.

                Nethertheless, I tried moving the object:


                var myStory = myDocument.createTOC(myTOCStyle, true, undefined, [myX1, myY1]);
                var myFrame = myStory[0].textFrames[0];
                myFrame.move(myTocPage);


                but I got the following error message:

                invalid object


                What's wrong?


                Thanks again!

                • 5. Re: Create TOC on active page
                  AdobeScripts Level 3

                  franzi_ska wrote:

                   

                  var myStory = myDocument.createTOC(myTOCStyle, true, undefined, [myX1, myY1]);
                  var myFrame = myStory[0].textFrames[0];
                  myFrame.move(myTocPage);


                  but I got the following error message:

                  invalid object

                   


                  What's wrong?

                   

                  I still don't understand why moving TF with TOC is wrong for you ? if something doesn't work - you need to find workaround

                   

                  the error is in myStory[0] - should be myStory.textFrames[0]

                   

                  robin

                   

                  www.adobescripts.co.uk

                  • 6. Re: Create TOC on active page
                    franzi_ska Level 1

                    From this point of view you're right, I have to find a workaround to avoid the problem (but I still want to knwo what's the problem about my script).


                    I tried your suggestion:

                     

                    var myStory = myDocument.createTOC(myTOCStyle, true, undefined, [myX1, myY1]);
                    var myFrame = myStory.textFrames[0];
                    myFrame.move(myTocPage);

                     

                    Now the problem lies in the 2nd line (Object is undefinied).

                     

                    I think var myFrame = myStory[0].textFrames[0]; is right as the toc returns an array of story.

                     

                    So the problem still excists...

                     

                    In any case: Thank you very much for helping me!

                    • 7. Re: Create TOC on active page
                      AdobeScripts Level 3

                      franzi_ska wrote:

                      var myStory = myDocument.createTOC(myTOCStyle, true, undefined, [myX1, myY1]);
                      var myFrame = myStory.textFrames[0];
                      myFrame.move(myTocPage);
                      

                       

                      Now the problem lies in the 2nd line (Object is undefinied).

                       

                      I think var myFrame = myStory[0].textFrames[0]; is right as the toc returns an array of story.

                       

                      So the problem still excists...

                      the problem is in InDesign version you use

                       

                      in CS3 and CS4 - you need to refer to textContainers instead of textFrames - now textFrames return array/collection of InLined/Anchored TextFrames

                       

                      robin

                       

                      www.adobescripts.co.uk

                      • 8. Re: Create TOC on active page
                        chrisnaylor Level 1

                        I had this same problem with MyGetBounds() in VBScript.

                         

                        You have to specify the Ruler Origin before calling MyGetBounds() as Page Origin - not spread.

                         

                        Otherwise, all goes well when you're placing and resizing text frames on an even-numbered (left hand) page; but, as soon as you try to use MyGetBounds() on an odd-numbered page it assumes you're measuring from top left of the spread, rather than the page, and positions the text frame over on the left-hand side of that spread - making it appear as if it's been placed on the wrong (preceding) page.

                         

                        You need (in VBScript):

                         

                        myDocument.ViewPreferences.RulerOrigin = idRulerOrigin.idPageOrigin