10 Replies Latest reply on Sep 2, 2013 10:51 PM by Ruq

    Automate manual work with Tables

    Ruq Level 1

      I am working on a project where I have a indd file containing tables which are mostly inconsistent in formatting.

      The workflow I have developed so far goes something like this:

       

      [Manual work]
      I select the source table, convert it to text, select the resulting text, followed by Find/Replace to remove extra returns and white space, then I copy the selected text to clipboard.
      Then I switch to another indd file where I paste the text, select the text again, convert it to table with proper table style. Select the resulting table. (The purpose of converting the table to text is to remove all the inconsistent formatting from the table.)

       

      [Script]
      With the help of good folks here at InDesign Scripting forum, I have developed a small script that sets the column width and row height of the table and applies a paragraph style to text of first cell of the table.

       

      [Manual work]
      Then I place my cursor after the table and manually enter the row count of the table and apply a specific paragraph style to the count.

       

      Is there any chance that I can automate the [Manual work] part.

      Namely:Eliminate multiple selection of same text/table.

      Insert the count of table rows after table.

       

       

      Thanks and regards.

        • 1. Re: Automate manual work with Tables
          DaveSofTypefi Level 2

          What criterion do you use to select the source table? Without that information, automation of this task is impossible, but everything else is probably doable -- I doubt it's really necessary to involve another document.

           

          Dave

          • 2. Re: Automate manual work with Tables
            Ruq Level 1

            Thanks DaveSofTypefi for the answer.

             

            I select the whole table at once using the arrow that appears when I hover over top-left edge of table.

             

            Using another indd file is also neccessary in my workflow.

             

            Thanks and regards.

            • 3. Re: Automate manual work with Tables
              DaveSofTypefi Level 2

              So there is only one table, is that right?

               

              Dave

              • 4. Re: Automate manual work with Tables
                Ruq Level 1

                Yes,

                 

                one table selected at a time.

                 

                Thanks and Regards.

                • 5. Re: Automate manual work with Tables
                  DaveSofTypefi Level 2

                  I'm sorry, I'm obviously not being clear. You said in your original message that you wanted to automate the selection of the table. So I said, how do I know which table to select?

                   

                  But now it sound as though you don't want to automate that part.

                   

                  How much scripting experience do you have? Are you hoping to learn how to do this? Or are you expecting someone to write a script for you?

                   

                  Dave

                  • 6. Re: Automate manual work with Tables
                    Ruq Level 1

                    Thanks Dave for your time and effort.

                     

                    In the first message I stated that "I select the source table". That is the starting point, from there I need the automation to start on that selected table.

                     

                    I have got my hands dirty with scripting and programming (VB.NET, C#). Javascript with InDesign is a bit new to me.

                     

                    I just need a outline script with key features implimented (as described in first message) like converting table to text and back to table with a perticular table style applied and so on, then I am capable to tweek it as needed.

                     

                    For example http://forums.adobe.com/message/5629973 , here I asked a question and Vamitul guided me by providing a snippet, then I adapted that to suit my need and reposted it.

                     

                    I am hoping to learn how to do it myself, if you can help me in building that script it would be great help.

                     

                    Many thanks and regards.

                    • 7. Re: Automate manual work with Tables
                      DaveSofTypefi Level 2

                      Having been burned badly in the past copying tables between documents, I'm reluctant to guide you down that path -- although in the description you posted in the opening message you never seem to be copying the table back into the original document -- is that right? You want to end up with the table in a different document?

                       

                      Why can't you do the tasks you describe in situ? In a script, you don't have to worry about what would be tedious and repetitive if done by hand.

                       

                      To identify a table from a selection you can use this function; just pass into it a reference to the selection, as shown:

                       

                       

                      myTable = getTable(app.selection[0]);
                      
                      function getTable(obj) {
                                if (obj instanceof Table) return obj;
                                obj = obj.parent;
                                if (obj instanceof Application == false) {
                                          return getTable(obj);
                                }
                                return null;
                      }
                      

                       

                      Now you have a reference to the table, you can manipulate it in many ways, including convert it to text if you insist.

                       

                      myText = myTable.convertToText("\t", "\r")

                       

                      Now you have a reference to the text -- notice that you don't have to select it to process it.

                       

                      I don't have any more time right now because the family is going out and I have to go with them.

                       

                      Dave

                      • 8. Re: Automate manual work with Tables
                        Ruq Level 1

                        Thanks Dave for the helpful answer.

                         

                        After reading your reply i figured out that this is what I actually needed.

                        I had no clue how to convert table to text and store that resulting text in a variable for further use.

                         

                        Thanks again for your reply.

                         

                        I will post my final working code as soon as it gets done.

                         

                        Please point out how to do a GREP find/change on text.

                         

                        Thanks and regards.

                        • 9. Re: Automate manual work with Tables
                          Vamitul Level 4

                          Ruq, to use the grep, first set the preferences using

                          app.findGrepPreferences      and

                          app.changeGrepPreferences

                           

                          Then

                          myText.changeGrep() or myText.findGrep().

                          both methods return an array of found texts, so if you need to manipulate those results remeber the cardinal rule of ALWAYS ITERATING THE ARRAY BACKWARDS, otherwise you might invalidate references to the found objects.

                           

                           

                           

                          @Dave:

                          Your getTable function has one problem. What if the selection is a story, or just a text, containing a table.

                          • 10. Re: Automate manual work with Tables
                            Ruq Level 1

                            Thanks.

                             

                            I will surely check that out.

                             

                            If possible please shed some light on how to switch documents via scripting.

                             

                            Normal scenerio is that I have 2 docs open.

                            doc1 is source doc2 is destination.

                            I need to copy text from doc1 and paste it into doc2.

                             

                            Thanks and regards.