7 Replies Latest reply on Oct 25, 2018 2:09 AM by prakashc39562731

    Unlock PageItem in InDesign page

    prakashc39562731 Level 1

      Dear All,

       

      I have tried to override pageitems in InDesign page. In master page the textframes are threaded while I try to override master page items in the first page of the inDesign document the frame thread is broken. I want only override threaded frame in the master page. Could you anyone help me to fix this issue.

      MasterPage.png

      After executing script i have get the following

      After.png

      Here is my code

       

       

      var mainFrame=getFrame(app.activeDocument.pages[0], "MainFrame");

      if(mainFrame!=$.global.undefined) {

          TextFlowForINTT(mainFrame);

      }

       

       

       

       

      function getFrame(myPage, labelString) {

          try {

              var myTextFrames = myPage.textFrames;

              for (var i = 0; i < myTextFrames.length; i++) {

                  if (myTextFrames[i].label.match(labelString))

                      return myTextFrames[i];

              }

          } catch (e) {

              new MyException("getFrame ", e, errorLogFile, true)

          }

       

       

      }

       

       

       

       

      function TextFlowForINTT(mainFrame) {

          try {       

                  var maxPageCount=0;

                  var myDoc = app.activeDocument; 

                  myDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

                  var myTextFrame = mainFrame.endTextFrame;

                  var gBounds=myTextFrame.geometricBounds;

                  while (myTextFrame.overflows) {

      maxPageCount++;

                  var newPage=myDoc.pages.add();           

                  var pageIndex=myDoc.pages.length-1;

                  OverrideMasterItemsOnlyForMainFrame(pageIndex,"MainFrame");

                  //app.menuActions.itemByName('$ID/Override All Master Page Items').invoke();       

                  var mainFrame=getFrame(newPage,"MainFrame");    

                  if(mainFrame!=$.global.undefined) {

                      mainFrame.label="MainFrame";

                      mainFrame.previousTextFrame = myTextFrame;

                      //myDoc.align(mainFrame, AlignOptions.LEFT_EDGES, AlignDistributeBounds.MARGIN_BOUNDS);

                      myTextFrame = myTextFrame.endTextFrame;  

                  }

      if(maxPageCount>800) {

      alert("overset found. script can't reflow the text into inDesign template.");

                        exit(0);

      }

              }

          } catch(e) {

             

          }  

      }

       

       

       

       

      function OverrideMasterItemsOnlyForMainFrame(pageIndex,mainFrameLabel) { 

          try {

                  var mainFrameArray=[];

                  var myDocument = app.activeDocument;

                  var targetPage=myDocument.pages[pageIndex];

                  if(targetPage.side==PageSideOptions.LEFT_HAND) {

                      var allItems = myDocument.pages[pageIndex].appliedMaster.pages[0].pageItems.everyItem().getElements();      

                  }else {

                      var allItems = myDocument.pages[pageIndex].appliedMaster.pages[1].pageItems.everyItem().getElements(); 

                  }

                 

                  for(var i=0;i<allItems.length;i++){ 

                      try{

                              if(allItems[i] instanceof TextFrame&&allItems[i].label==mainFrameLabel) {

                                //  var newFrames = threadOverride(sourceSpread, allItems[i], destPage);

                                  allItems[i].allowOverrides = true;

                                  //mainFrameArray.push(allItems[i]);

                                  allItems[i].override(targetPage);

                              } 

                          }       

                      catch(e){

                      } 

                  }

                  //app.select(mainFrameArray);

                  //app.selection[0].override(targetPage);           

                  //app.selection[1].override(targetPage);

              }catch(e) {

                      $.writeln(e);

              }

       

      Thanks ,

      Prakash C

       

      this post moved to InDesign Scripting forum. (Moderator)