10 Replies Latest reply on Jan 28, 2014 11:19 AM by Liphou

    [JS] Table RowTypes.BODY_ROW

    Liphou Level 1

      Hello,

      Is it possible to simplied this loop?

      And she'll ask me if I have a problem SEVERAL line feet ... I'll have to be more présit


      thank you

      // -----

      Bonjour,

       

      Est-il possible de simplié cet boucle?

      Et elle vas me poser un problème si j'ai plusieur ligne de pieds ... je vais devoir être plus présit

      Merci

       

       

      for (y = (monTableau.rows.length-1); y >= 0; y--) {

         if (monTableau.rows[y].rowType != RowTypes.BODY_ROW) {   

              monTableau.rows[y].rowType = RowTypes.BODY_ROW; // OK  convertion ligne d'en-tete

          }

      }

        • 1. Re: [JS] Table RowTypes.BODY_ROW
          Peter Kahrel Adobe Community Professional & MVP

          Header rows have to be converted last to first, which is what we'd expect. But bizarrely, you have to convert footer rows from first to last. So header rows and footer rows need to be converted in separate loops:

           

          tetes = monTableau.headerRowCount;
          for (y = tetes-1; y >= 0; y--) {
              monTableau.rows[y].rowType = RowTypes.BODY_ROW;
          }
          
          start = monTableau.bodyRowCount;
          stop = start+monTableau.footerRowCount;
          for (y = start; y < stop; y++) {
              monTableau.rows[y].rowType = RowTypes.BODY_ROW;
          }
          

           

          Peter

          • 2. Re: [JS] Table RowTypes.BODY_ROW
            Harbs. Level 6

            Peter Kahrel wrote:

             

            But bizarrely, you have to convert footer rows from first to last...

            Makes sense to me. You can't have body rows above header rows or below footer rows.

             

            Harbs

            • 3. Re: [JS] Table RowTypes.BODY_ROW
              Peter Kahrel Adobe Community Professional & MVP

              > Makes sense to me. You can't have body rows above header rows or below footer rows.

               

              Just testing

               

              Ok, not so bizarre, you're absolutely right.

               

              Peter

              • 4. Re: [JS] Table RowTypes.BODY_ROW
                Marc Autret Level 4

                What about:

                 

                monTableau.rows.everyItem().properties = {rowType: RowTypes.BODY_ROW};
                

                 

                ?

                 

                @+

                Marc

                 

                [EDIT: Doesn't seem to work as expected. Weird…]

                • 5. Re: [JS] Table RowTypes.BODY_ROW
                  Liphou Level 1

                  Hello/Bonsoir Marc,



                  I just did a little test with your command line:

                  je vien de faire un petit test avec ta ligne de commande :

                  First pass:

                  Première passe :

                   

                  $.writeln ('AV :' +monTableau.headerRowCount + ' headerRow'); // conte le nombre de ligne d'en-tête

                  $.writeln ('AV :' + monTableau.footerRowCount + ' footerRow'); // conte le nombre de ligne de pied de page

                   

                  monTableau.rows.everyItem().properties = {rowType: RowTypes.BODY_ROW};

                   

                  $.writeln ('AP :' +monTableau.headerRowCount+ ' headerRow'); // conte le nombre de ligne d'en-tête

                  $.writeln ('AP :' +monTableau.footerRowCount  + ' footerRow'); // conte le nombre de ligne de pied de page

                   

                  Result: (biza)

                  Résulta : (biza)

                  AV :2 headerRow

                  AV :2 footerRow

                  AP :1 headerRow

                  AP : 0 footerRow

                   

                  second pass :

                   

                  AV :1 headerRow

                  AV : 0 footerRow

                  AP : 0 headerRow

                  AP : 0 footerRow

                   

                   

                  @Peter

                   

                  $.writeln ('AV :' +monTableau.headerRowCount + ' headerRow'); // conte le nombre de ligne d'en-tête

                  $.writeln ('AV :' + monTableau.footerRowCount + ' footerRow'); // conte le nombre de ligne de pied de page

                   

                  tetes = monTableau.headerRowCount;

                  for (y = tetes-1; y >= 0; y--) {

                      monTableau.rows[y].rowType = RowTypes.BODY_ROW;

                  }

                   

                  start = monTableau.bodyRowCount;

                   

                  for (y = start; y < (monTableau.rows.length); y++) { // petit modification

                      monTableau.rows[y].rowType = RowTypes.BODY_ROW;

                  }

                   

                  $.writeln ('AP :' +monTableau.headerRowCount+ ' headerRow'); // conte le nombre de ligne d'en-tête

                  $.writeln ('AP :' +monTableau.footerRowCount  + ' footerRow'); // conte le nombre de ligne de pied de page

                   

                   

                  First pass:

                  Première passe :

                  AV : 2 headerRow

                  AV : 2 footerRow

                  AP : 0 headerRow

                  AP : 0 footerRow

                   

                  Thank you all

                  Merci à vous tous

                  • 6. Re: [JS] Table RowTypes.BODY_ROW
                    Jump_Over Level 5

                    Hi,

                     

                    I was wondering about "everyItem() way" but test failed indeed...

                    Looks like it works step by step, row by row...

                     

                    Jarek

                    • 7. Re: [JS] Table RowTypes.BODY_ROW
                      Marc Autret Level 4

                      Hi Jarek,

                       

                      I finally understood (I think) why the plural command fails for header rows while it works like a charm for footer rows.

                       

                      1. Indeed, when myTable.rows.everyItem().properties=… is executed, rows are processed by increasing index. But row[ i ] cannot be set to BODY_ROW as long as row[ i+1 ] is a HEADER_ROW. Therefore row[0], row[1], ..., row[headerRowCount-2] are not converted into BODY_ROW and the command continues its course on the remaining rows. (As you know, the syntax everyItem().properties=obj bypasses unproper assignments.) By contrast, the last rows are properly set to BODY_ROW, as there is no problem in converting footer rows into body rows by increasing index. This is exactly what Harbs and Peter remarked above.

                       

                      2. Now, an interesting question: can we control the order by which items are processed through a plural specifier? As to everyItem(), I don't think so. But itemByRange() seems to open up possibilities…

                       

                      Ideally one would like to do:

                       

                      rows.itemByRange( headerRowCount-1, 0 ).properties = obj;  // descending indexes for header rows

                        and

                      rows.itemByRange( -footerRowCount, -1 ).properties = obj;  // ascending indexes for footer rows

                       

                      The footer part works fine (as expected), but the header stuff still leads to the original issue—only the last header row is converted.

                       

                      3. However, the specifier is properly parsed "…row[N] to …row[0]" as revealed by toSpecifier(). In my view the rows are passed in the desired order, BUT something else overrides this option…

                       

                      4. It's time to remember that Row and Column objects are just 'wigs' over actual Cells. Behind the scenes, our range of rows still needs to be resolved as a pure range of cells. During this process I suspect that the subsystem reorders the implied targets in an optimal way. So "…row[N] to …row[0]" silently becomes "…cell[0] to …cell[idx]" and our efforts in vain! Well. This reasoning has led me to try a more explicit approach: instead of using myTable.rows.itemByRange(N,0)… let's directly provide the descending cell range: myTable.cells.itemByRange(idx,0).

                      And you know what? …

                       

                      // var myTable = ...
                      
                      var o = {rowType: +RowTypes.BODY_ROW},
                          x;
                      
                      if( x=myTable.headerRowCount )
                          {
                          x = myTable.rows[x-1].cells[-1].id;
                          myTable.cells.itemByRange(x,0).properties = o;
                          }
                      
                      if( x=myTable.footerRowCount )
                          myTable.rows.itemByRange(-x,-1).properties = o;
                      

                       

                      Is this snippet significantly more effective than existing solutions based on array loops? That's not my point. Just sharing my theory on ordering commands on cell ranges.

                       

                      @+

                      Marc

                      • 8. Re: [JS] Table RowTypes.BODY_ROW
                        Jump_Over Level 5

                        Yo Marc,

                         

                        If  I only would have your flashlight instead of my candle walking through the InDesign maze...

                         

                        Jarek

                        • 9. Re: [JS] Table RowTypes.BODY_ROW
                          Peter Kahrel Adobe Community Professional & MVP

                          Nice one, Marc. Thanks.

                           

                          Peter

                          • 10. Re: [JS] Table RowTypes.BODY_ROW
                            Liphou Level 1

                            Super analysis thank you Marc! I agree with the remark Jarek.