6 Replies Latest reply on Feb 10, 2016 1:27 AM by Loic.Aigon

    [JS] cell position on what page

    Liphou Level 1

      Hello,
      I try to locate the page or is a table cell.
      This table is on several pages?

      Currently I always returns the page's ink table.

      Thank you for all the possible information.

       

      -----------------------------------------

      Bonjour,

      Je cherche à localiser la page ou se situe cellule d'un tableau.

      Ce tableau est sur plusieurs pages?

       

      Actuellement, je retourne toujours la page où est encre le tableau.

       

      Merci pour toutes les infos possibles.

        • 1. Re: [JS] cell position on what page
          Laubender Adobe Community Professional & MVP

          Hi Liphou,

          did you try parentTextFrames[0].parentPage method for insertionPoints[0] of a text cell?

           

          However, if the first parentTextFrame of the cell (and there could be no other), is located on the pasteboard you'll get null as result.

          Also, if the cell resides in overset text or the cell itself is overset and there is no insertionPoint visible, there could be some unpleasant surprises.

           

          Uwe

          • 2. Re: [JS] cell position on what page
            Loic.Aigon Adobe Community Professional

            Hi,

            Indeed any cell is related to its parent which is itself related to an "character". An alternative is to create a dummy pageItem that host the parentPage property. Be aware that it will only work in CS5+ as CS4- don't have a parentPage property.

             

            var main = function(){
              var cell, pi, cellHeight, cellGrow, page;
            
              if ( !app.documents.length
              || app.selection.length!=1
              || !(app.selection[0] instanceof Cell) ) {
              alert("You need to select a table cell object!");
              return;
              }
              cell = app.selection[0];
              cellGrow = cell.autoGrow;
            
            
              cellHeight = cell.height;
              cell.autoGrow = true;
              pi = cell.insertionPoints[0].rectangles.add();
              pi = cell.rectangles.itemByID(pi.id);
              page = pi.parentPage;
              pi.remove();
              cell.height = cellHeight;
              cellGrow = cell.autoGrow;
              return page; //possibly null
            }
            var u;
            app.doScript("main();",u,u,UndoModes.ENTIRE_SCRIPT, "GetPage");
            
            

             

            HTH

             

            Loïc

            www.ozalto.com

            • 3. Re: [JS] cell position on what page
              Liphou Level 1

              Loïc thank you, thank you Laubender,



              if (lesTableaux[g].cells[t].contents != '') { // If contenu de cell
                        if (testPage(lesTableaux[g].cells[t].paragraphs[0]) == o.laPagePaire.name || testPage(lesTableaux[g].cells[t].paragraphs[0])  ==  o.laPageImpaire.name) {
                               //$.writeln ((testPage(lesTableaux[g].cells[t]) == o.laPagePaire.name) + ' — '+ testPage(lesTableaux[g].cells[t])  ==  o.laPageImpaire.name);
                               recupLesPara(lesTableaux[g].cells[t].paragraphs);
                          } // if test pages  
              }// fin If contenu de cell
              ...
              ...
              function testPage(testSelection) { 
                        return(Number(testSelection.parentTextFrames[0].parentPage.name));
              } //
              

               

              I succeeded in what I wanted, when I test my cell is empty.

              The script and for CS6 release.

              Loïc, thank you for your reply, I have the peel to understand all its subtlety !!! thank you.

              -----------------


              Merci Loïc, Merci Laubender,

               

              je suis parvenu à ce que voulais, je ai du test quand ma cellule est vide.

               

              Le script et pour une version CS6.

               

              Loïc, merci pour ta réponse, je dois la decortiqué pour bien comprendre toute sa subtilité !!! merci  

              • 4. Re: [JS] cell position on what page
                Loic.Aigon Adobe Community Professional

                Nevermind, Uwe's answer is fully efficient. You don't need my uber complicated stuff. I thought you will eventually always get the initial page but I was wrong.

                • 5. Re: [JS] cell position on what page
                  Laubender Adobe Community Professional & MVP

                  Hi Loïc, there always cases

                   

                  my method would lead to wrong results (geometrically spoken), if the cell leaves the page, because:

                  1. The table extends to a different page

                  2. The table extends to the pasteboard

                  leaving or not leaving the text frame.

                   

                  With your method you are probing a rectangle inside a cell, not the parent text frame of some rows in a table.
                  Geometrically spoken, this is more precise and circumvent the cases above.

                   

                  Uwe

                  • 6. Re: [JS] cell position on what page
                    Loic.Aigon Adobe Community Professional

                    @Liphou,

                     

                    Just for knowledge, the goal of my snippet was to add a temporary page item within the cell in order to get access to the parentPage property of that object.

                     

                    LOic