9 Replies Latest reply on Aug 30, 2016 11:57 AM by Loic.Aigon

    In textFrame Last Row appliedCellStyle

    karthiks94217840 Level 2

      Dear Friends,

       

      I need your help;

       

      How to appliedCellStyle(row) for continued tables first text frame end of the row?. I have place the code is below, but not working.

       

      Please suggest friends! what can i do?

       

      var myTable = app.activeDocument.stories.everyItem().tables[0].rows.everyItem();
      var myCell = myTable.cells.everyItem().getElements();  
      for(var n=0;n<myCell.length-1;n++){  
      
      
      var cell1 = myCell[n].texts[0].insertionPoints[0].parentTextFrames[0].id;  
      var cell2 = myCell[n].texts[0].insertionPoints[0].parentTextFrames[0].parentPage;  
      var cell3 = myCell[n].texts[0].insertionPoints[0].parentTextFrames[0].parentPage.documentOffset; 
      
      
      cell3.appliedCellStyle = "TBL_row";
      
      
      
      
      

       

      I have attached screenshot also:

       

      InPut:

       

      Input.png

       

      OutPut:

       

       

      Output.png

       

      I need to help friends.

       

      Thanks in Advance

      Ks

        • 1. Re: In textFrame Last Row appliedCellStyle
          Loic.Aigon Adobe Community Professional

          You may try to loop through rows and see if the parent text frame id is consistent with the id of the first container. Otherwise it means it has changed:

           

          var ns = {};
          
          
          ns.fixTable = function( t ) {
            var rows = t.rows, 
            tf=t.cells[0].texts[0].parentTextFrames[0],
            tfId = tf.id,
            i = 0, n = rows.length,
            row;
          
            for ( i = 0; i< n; i++ ) {
            row = rows[i];
            if ( rows[i+1].isValid && rows[i+1].cells[0].insertionPoints[0].parentTextFrames[0].id != tf.id ) {
            row.cells.everyItem().appliedCellStyle = "BLUE";
            break;
            }
            }
          }
          
          
          ns.main = function() {
          
            var doc = app.properties.activeDocument,
            sts, st, t, cellText;
            if (!doc ) return;
          
            sts = app.activeDocument.stories.everyItem().getElements();  
            while ( st = sts.pop() ) {
            t = st.tables[0];
            cellText = t.cells[0].insertionPoints[0];
            cellText.parentTextFrames.length 
            && cellText.parentTextFrames[0].isValid
            && ns.fixTable( t );
            }
          };
          
          
          
          
          
          
          ns.main();
          
          
          delete ns;
          ns = null;
          

           

           

          HTH

           

          Loic

          www.ozalto.com

          • 2. Re: In textFrame Last Row appliedCellStyle
            Kai Rübsamen Level 4

            Hi Guys,

             

            I wrote something similiar a while ago:

             

            main();
            
            function main() {
            
              var curDoc = app.documents[0];
              var allTables = curDoc.stories.everyItem().tables.everyItem().getElements();
              var nTables = allTables.length;
            
              var testID = 0;
            
              for (var t = 0; t < nTables; t++) {
                var curTable = allTables[t];
                var allRows = curTable.rows;
                var nRows   = allRows.length;
                
                for (var r = 0; r < nRows; r++) {
                  var curRow = allRows[r];
                  var iP = curRow.cells[0].insertionPoints[0];
                  var parTFrameID = iP.parentTextFrames[0].id;
            
                  if (testID != 0 && testID != parTFrameID) {
                    var c = allRows[r-1].cells.everyItem();
                    c.bottomEdgeStrokeWeight = curTable.bottomBorderStrokeWeight;
                  }
                  testID = parTFrameID;
                }
              }
            }
            

             

            @Loic: I’m interested in your code, but didn’t understand everything. It would be great, if you can explain some parts:

             

            1. What is the benefit of the global object ns ?

            2. Why is there a need for 'delete' and assigning a value of 'null'?

            3. Normally I wrote 'function main()' > you wrote ns.main = function()  >> why? I think, Marc did it the same way. Since Marcs coding is really hard for me to read, I try to understand, why you guys do it in this way …

            4. Why app.properties.activeDocument instead of app.activeDocument ?

             

            Thanks

            Kai

            • 3. Re: In textFrame Last Row appliedCellStyle
              Loic.Aigon Adobe Community Professional

              Hi Kai,

              I think, Marc did it the same way…

              Well, clearly Marc is a great source of inspiration to me, no misteries

               

              1. What is the benefit of the global object ns ?

              2. Why is there a need for 'delete' and assigning a value of 'null'?

               

              It's just a current attempt of dealing with memory management. It's not needed here but I try to take good habits. Pointing to a "namespace" object may allow deleting this object thus releasing it for the garbage collector.

               

              Marcs coding is really hard for me to read…

              Marc has his own great logic. I won't say I understand all of it but I try to get inspired as much as possible.

               

              4. Why app.properties.activeDocument instead of app.activeDocument ?

              It allows reducing the need of code. Actually I took this from Marc and I never told him how smart that is, so Marc if you are around, this line is brilliant.

              app.properties.activeDocument will return undefined. It avoids dealing with if(app.documents.length… avoiding a scope on the fly.

               

              HTH

               

              Loic

              • 4. Re: In textFrame Last Row appliedCellStyle
                Kai Rübsamen Level 4

                Thanks for your reply. Any comments on point no. 3??

                 

                Kai

                • 5. Re: In textFrame Last Row appliedCellStyle
                  karthiks94217840 Level 2

                  Hi Loci,

                   

                  Thanks to your first reply!

                   

                  I have try to your script, but i got one error for "Object is invalid"? I have attached screenshot below:

                   

                  Loic.png

                   

                  Please suggest friends! what can i do?

                   

                  Thanks in Advance

                  KS

                  • 6. Re: In textFrame Last Row appliedCellStyle
                    karthiks94217840 Level 2

                    Hi Kai,

                     

                    Thanks to your reply! One more thanks again you are helping me.

                     

                    Also, I have try to your code, but i got one error for "Undefined is not an object"? I have attached screenshot below:

                     

                    One more thing below code for missing in the appliedCellStyle = "Last_row"?

                    kai.png

                    Please suggest friends! what can i do?

                     

                    Thanks in Advance

                    KS

                    • 7. Re: In textFrame Last Row appliedCellStyle
                      Kai Rübsamen Level 4

                      Both scripts work perfect, if you have no overset!

                      • 8. Re: In textFrame Last Row appliedCellStyle
                        Loic.Aigon Adobe Community Professional

                        Kai Rübsamen a écrit:

                         

                        Thanks for your reply. Any comments on point no. 3??

                         

                        Kai

                        It's just a regular to the object's method like you call your function.

                        • 9. Re: In textFrame Last Row appliedCellStyle
                          Loic.Aigon Adobe Community Professional

                          Replace this line of code :

                           

                          cellText.parentTextFrames.length  

                          && cellText.parentTextFrames[0].isValid 

                          && ns.fixTable( t );

                           

                          by

                           

                          t.isValid

                          && cellText.parentTextFrames.length  

                          && cellText.parentTextFrames[0].isValid 

                          && ns.fixTable( t );

                           

                          The error is thrown as some story must not have any child tables.