2 Replies Latest reply on Mar 28, 2016 2:16 PM by brianc49423945

    InsertionPoint on last page?

    brianc49423945

      I'm having an issue getting the InsertionPoint on a page (last page).

       

      My script currently looks for a script label called "INDEX" in a text frame. What is happening is the contents are been posted into the Master Page, and the page created from the Master Page.

      I only want the content posted into the insertion point on the last page. Master Pages should be untouched.

       

      Any pointers would greatful.

       

      Here is my script.

       

          // Find the last page and get all the text frames
          var lastPageNumber=myDoc.pages.count()-1;
          var lastPage= app.activeDocument.pages.item(lastPageNumber);
          var lastPageItems= lastPage.masterPageItems;
          var indexFrame;
          for(i=0;i<lastPageItems.length;i++){
              if (lastPageItems[i].label=="INDEX"){ // look for textFrame with the script label "INDEX"
                  indexFrame=lastPageItems[i];
                              }
          }
        
          // Find the insertion point into the text frame
          var indexInsertionPoint=indexFrame.parentStory.insertionPoints[];
        • 1. Re: InsertionPoint on last page?
          Vamitul Level 4

          you first need to override your frame. Also, your code goes through quite a lot of unnecessary hoops:

           

          (function(){
              function getIndexFrame(pag){
                  var masterPI=pag.masterPageItems;
                  for (var i=0; i<masterPI.length;i++){
                      if (masterPI[i].hasOwnProperty('label')&&masterPI[i].label=='INDEX'){
                          return masterPI[i];
                      }
                  }
              }
              var doc=app.activeDocument;
              var lastPage=doc.pages[-1];
              var indexFrame=getIndexFrame(lastPage);
              //override the frame;
              var newFrame=indexFrame.override(lastPage);
              //depening on document settings and it's history, the page item can shift it's position. 
              if (newFrame.parentPage!==lastPage){
                  newFrame.move(lastPage);
              }
              newFrame.geometricBounds=indexFrame.geometricBounds;
          
          
              //do nasty things with your new index frame:
              newFrame.insertionPoints[-1].contents='This is a nasty thing to do to an index frame!!';
              
          }());
          
          • 2. Re: InsertionPoint on last page?
            brianc49423945 Level 1

            Thanks Vamitul for the detailed reply.I can a learn a few things from your code.

            When I saw the overriding the frame, I had a face in palm moment.

             

            It worked very well within my code.