6 Replies Latest reply on Jul 20, 2015 2:22 AM by Johnwhite

    How define table

    Johnwhite Level 1

      Hi experts,

       

      I have a script for find table and change properties.

      Could someone show me how to make it works.

       

      Regard

      John

       

                              myDoc = app.activeDocument;

                              findTable();

                              function findTable(){

                                  for ( s = myDoc.stories.length-1; s >= 0; s-- ){

                                      for ( t = myDoc.stories[s].tables.length-1; t >= 0; t-- ){

                                          myTable = myDoc.stories[s].tables[t];

                                          tables[t].cells.everyItem().texts.everyItem().fillColor = "Black";

                                          tables[t].cells.everyItem().fillColor = "None";

                                          tables[t].cells.everyItem().leftEdgeStrokeColor = "None";

                                          tables[t].cells.everyItem().rightEdgeStrokeColor = "None";

                                          tables[t].cells.everyItem().topEdgeStrokeColor = "None";

                                          tables[t].cells.everyItem().bottomEdgeStrokeColor = "None";

                                      }

                                  }

                              }

                          alert("Finish.") 

        • 1. Re: How define table
          BSKTCreation Level 2

          Hi John,

           

          I've made a few changes but kept things similar to your original code, let me know how you go.

           

          var myTables = app.documents[0].stories.everyItem().tables.everyItem().getElements()
          
          
          findTable();
          
          
          function findTable(){
              for ( t = 0; t < myTables.length; t++ ){
                  myTables[t].cells.everyItem().texts.everyItem().fillColor = "Black";
                  myTables[t].cells.everyItem().fillColor = "None";
                  myTables[t].cells.everyItem().leftEdgeStrokeColor = "None";
                  myTables[t].cells.everyItem().rightEdgeStrokeColor = "None";
                  myTables[t].cells.everyItem().topEdgeStrokeColor = "None";
                  myTables[t].cells.everyItem().bottomEdgeStrokeColor = "None";
                  }
              }
          
          
          
          
          
          

           

          Regards,

          Brett

          • 2. Re: How define table
            Johnwhite Level 1

            THANK YOU BRETT,

             

            In your expression, if I open some docs in which some docs are no such table, the script will give me an error.

             

            my goal is find table in all open docs and then change the properties.

             

            Regard

            John

            • 3. Re: How define table
              Vamitul Level 4

              Hi John.

              If your goal is to find all tables in all documents, you will need another "for" loop to go through each open document.

              something like:

              var docs=app.documents;
              for (var i=0; i<docs.length; i++){
                  findTable(docs[i]);
              }
              function findTable(doc) {
                  for (var s = doc.stories.length - 1; s >= 0; s--) {
                      for (var t = doc.stories[s].tables.length - 1; t >= 0; t--) {
                          myTable = doc.stories[s].tables[t];
                          tables[t].cells.everyItem().texts.everyItem().fillColor = "Black";
                          tables[t].cells.everyItem().fillColor = "None";
                          tables[t].cells.everyItem().leftEdgeStrokeColor = "None";
                          tables[t].cells.everyItem().rightEdgeStrokeColor = "None";
                          tables[t].cells.everyItem().topEdgeStrokeColor = "None";
                          tables[t].cells.everyItem().bottomEdgeStrokeColor = "None";
                      }
                  }
              }
              
              

              Please also note the use of "var" for all variables, including the counters in the loops. You should make a habit of using it because otherwise it will come back to bite you when you least expect it.

              Also note that the code above won't deal with tables in footnotes or nested tables.

              • 4. Re: How define table
                Johnwhite Level 1

                thank you Vamitul

                 

                I changed it into this:

                 

                #target indesign

                       var docs = app.documents;

                                for (i = docs.length-1; i >= 0; i--) {

                                    var myTables = docs[i].stories.everyItem().tables.everyItem().getElements() 

                                        for ( t = 0; t < myTables.length; t++ ){ 

                                                myTables[t].cells.everyItem().texts.everyItem().fillColor = "Black"; 

                                                myTables[t].cells.everyItem().fillColor = "None"; 

                                                myTables[t].cells.everyItem().leftEdgeStrokeColor = "None"; 

                                                myTables[t].cells.everyItem().rightEdgeStrokeColor = "None"; 

                                                myTables[t].cells.everyItem().topEdgeStrokeColor = "None"; 

                                                myTables[t].cells.everyItem().bottomEdgeStrokeColor = "None"; 

                                                } 

                                            }

                                       

                                                       

                                                       

                                        var docs = app.documents;

                                             for (var i = docs.length-1; i >= 0; i--) {

                                                 if(docs[i].saved == false){

                                                       docs[i].close(SaveOptions.NO);

                                                     }

                                                 else if(docs[i].close(SaveOptions.YES));

                                              }

                                       

                                       

                                           alert("Finish.")

                 

                 

                it works

                 

                thank you so much

                John

                • 5. Re: How define table
                  Vamitul Level 4

                  You are welcome, but:

                  1) the counter variables are still used globally,

                  2) you don't need to redefine the docs variable

                  3) if one of the documents does not contain any tables,you will still get an error.

                   

                  Just for the fun of it (ignoring point 3) here is a two-liner that does everything:

                  app.documents.everyItem().stories.everyItem().tables.everyItem().cells.everyItem().propert ies={fillColor:'None',leftEdgeStrokeColor:'None',rightEdgeStrokeColor:'None',topEdgeStroke Color:'None',bottomEdgeStrokeColor:'None'};

                  app.documents.everyItem().stories.everyItem().tables.everyItem().cells.everyItem().texts.e veryItem().fillColor = "Black";

                  • 6. Re: How define table
                    Johnwhite Level 1

                    thank you Vantiful

                    thank you so much.