9 Replies Latest reply on Jun 18, 2010 4:37 AM by PankChat

    Select previous page items or next page items (IDCS3)

    PankChat Level 1

      Hello all,

       

      How can I refer to previous page or its item? I am trying to do something below. if a textFrame with label "myFrame" is missing on current page go to next page (or may try to next page)

       

      for (var i=0; i<=myTotalPage-1; i++)
      {
      app.activeWindow.activePage =myDoc.pages[i];
      //$.writeln ("Page is :"+myDoc.pages[i].name);
      if(!(myDoc.pages[i].textFrames.itemByName("sections")!=null))
      {
      var myText="sometext";
      myDoc.pages[i].previousItem ().textFrames.itemByName("myFrame").insertionPoints.item(-1).properties = { appliedCharacterStyle : "myCharacterStyle", contents:myText};
      }
      else{
      var myText="anotherText";
      myDoc.pages[i].textFrames.itemByName("myFrame").insertionPoints.item(0).properties = { appliedCharacterStyle : "myCharacterStyle", contents:myText};
      }
      I know that previousItem () is not supported here, just added it to make the things clear.
      Any suggestions greatly appreciated.
      TIA,
      --PC
        • 1. Re: Select previous page items or next page items (IDCS3)
          Kasyan Servetsky Level 5

          Try to reference next/previous page like so:

           

          var myPage = myDoc.pages[i];
          var myPreviousPage = myDoc.pages.previousItem(myPage);
          var myNextPage = myDoc.pages.nextItem(myPage);
          

           

          Kasyan

          • 2. Re: Select previous page items or next page items (IDCS3)
            Harbs. Level 6

            Or you can just use the documentOffset:

             

            prevPage = doc.pages.item(page.documentOffset+1);

            nextPage = doc.pages.item(page.documentOffset+1);

             

            fivePagesLater = doc.pages.item(page.documentOffset+5);

             

            Harbs

            • 3. Re: Select previous page items or next page items (IDCS3)
              Larry G. Schneider Adobe Community Professional & MVP

              Harbs,

               

              Did you possibly mean -1 for previous page?

              • 5. Re: Select previous page items or next page items (IDCS3)
                PankChat Level 1

                Thanks Kasyan, Harbs. I shall give a try and revert.

                 

                --PC

                • 6. Re: Select previous page items or next page items (IDCS3)
                  PankChat Level 1

                  Well I tried using Kasyan's suggestion but it outputs me error (object is

                  not valid). I thought var myPreviousPage =

                  myDoc.pages.previousItem(myPage); will suffice to pass the reference for

                  the previous page and to select the items of that page.

                  May be the selection syntax is not correct.

                   

                  In fact I have another challenge here. I also need to loop whether the

                  previous page do contains the "myFrame" or not. If it is not keep going

                  back (or may be forward- I will check the condition) to find a page with

                  "myFrame" textFrame.

                   

                  for (var i=0; i<=myTotalPage-1; i++)

                   

                  {

                  var myPage = myDoc.pages[i];

                  var myPreviousPage = myDoc.pages.previousItem(myPage);

                  var myNextPage = myDoc.pages.nextItem(myPage);

                   

                  app.activeWindow.activePage =myDoc.pages[i];

                  if(!(myDoc.pages[i].textFrames.itemByName("myFrame")!=null))

                  {

                  var myText="sometext";

                   

                  myPreviousPage.textFrames.itemByName("myFrame").insertionPoints.item(-1).properties

                  = { appliedCharacterStyle : "myCharacterStyle", contents:myText}; //ERROR

                  ON THIS LINE

                  }

                  else{

                  var myText="someothertext";

                   

                  myDoc.pages[i].textFrames.itemByName("myFrame").insertionPoints.item(0).properties

                  = { appliedCharacterStyle : "myCharacterStyle", contents:myText};

                  }

                   

                  Time to brush up my JS skills.

                   

                  --PC

                  • 7. Re: Select previous page items or next page items (IDCS3)
                    PankChat Level 1

                    Ok Fine!!!! if I use Next page option instead of previous page

                    (Strange!!!!!!! Does ID looks forward and ignore back pages in this case

                    or what?) it works and of course fails for the last page !!!!! Time to

                    resolve the loop issue.

                     

                    if(!(myDoc.pages[i].textFrames.itemByName("sections")!=null))

                    {

                    var myText="sometext";

                    myNextPage.textFrames.itemByName("sections").insertionPoints.item(0).properties

                    = { appliedCharacterStyle : "myCharacterStyle", contents:myText};

                     

                    TIA,

                    --PC

                    • 8. Re: Select previous page items or next page items (IDCS3)
                      PankChat Level 1

                      Hello again,

                      Kasyan's suggestion

                       

                      var myPreviousPage=mydoc.pages[i].previousItem(myPage);

                       

                      do not prompt for any error if selected first page.

                       

                      Harbs suggestion though prompts error if selected first page (obviously there is no  previous page)

                      var myPreviousPage = doc.pages.item(page.documentOffset+1);

                       

                      but both of them fails if I try

                       

                      myPreviousPage.textFrames.itemByName("myFrame").insertionPoints.item(-1).properties

                      = { appliedCharacterStyle : "myCharacterStyle", contents:myText}; //Object is invalid

                       

                       

                      but works for the next page (at least Kasyan's suggestion: not tested Harbs idea).

                       

                      myNextPage.textFrames.itemByName("myFrame").insertionPoints.item(0).properties

                      = { appliedCharacterStyle : "myCharacterStyle", contents:myText};

                       

                       

                      I beleive this has nothing to do with insertionPoints(-1) I am trying for myPreviousPage case and ID do look for back pages???????? Simply getting nuts.

                       

                      Any ideas???

                       

                      --PC

                      • 9. Re: Select previous page items or next page items (IDCS3)
                        PankChat Level 1

                        Just to clear the confusion

                         

                        but both of them fails if I try

                         

                        myPreviousPage.textFrames.itemByName("myFrame").insertionPoints.item(-1).propert ies

                        = { appliedCharacterStyle : "myCharacterStyle", contents:myText}; //Object is invalid

                         

                         

                        Even the selected page is not first page and previous page has textframe labelled "myFrame".