1 Reply Latest reply on Dec 4, 2014 3:49 AM by Sajeev Sridharan

    I have two textframes on one page. But when iterating using everyitem() it picks second prior to first?

    LearnIndesignScripting


      Hi Expert's


      I have two textframes on one page. But when iterating using everyitem() it picks second prior to first?

       

      var ObjDoc = app.activeDocument;
      var LstPara = ObjDoc.pages.everyItem().textFrames.everyItem().paragraphs.everyItem().getElements();

      for(var c1=0;c1<LstPara.length;c1++)
      {       
           var par = LstPara[c1];
           $.writeln(par.contents.toString());
      }


      is there any specific reason for that? Please explain

       

        • 1. Re: I have two textframes on one page. But when iterating using everyitem() it picks second prior to first?
          Sajeev Sridharan Level 4

          To solve your issue, try the below code:

           

          
          
          var ObjDoc = app.activeDocument;
          var LstTxtFrame = ObjDoc.pages.everyItem().textFrames.everyItem().getElements();
          
          
          for(var c1=LstTxtFrame.length-1;c1>=0;c1--)
          {        
              var LstPara = LstTxtFrame[c1].paragraphs.everyItem().getElements();
              for(var c2=0;c2<LstPara.length;c2++)
              {
                  var par = LstPara[c2];
                  $.writeln(par.contents.toString());
              }
          }
          

          I have two textframes on one page. But when iterating using everyitem() it picks second prior to first?

          is there any specific reason for that? Please explain

           

          InDesign text frames will work in LIFO (Last in first out) method, i.e., the last created text frame will be treated as a first frame in for loop, hence try the above code.

           

          Vandy