2 Replies Latest reply on Jun 20, 2017 11:21 AM by Luca_from_italy

    Array of tables all without the last

    Luca_from_italy

       

       

      128/5000

       

      I need to create an array of tables without the last, because the last one is used to update all the others and find new item.

      I wrote a script that updates the data entered from the last table, but does not highlight the new item that are in the last table

      I tried with itemByRange but all the tables have index 0

      can someone help me?

      thanks

        • 1. Re: Array of tables all without the last
          Loic.Aigon Adobe Community Professional

          You can use getElements() to retrieve inner elements from the itemByRange method. That way you can introspect every single table and its properties.

          var tables = app.activeDocument.textFrames[0].parentStory.tables;
          tables = tables.itemByRange ( 0, -2).getElements();
          alert( tables[0].index +" vs "+ tables[tables.length-1].index );
          

           

          Capture d’écran 2017-06-20 à 10.17.51.png

           

          Capture d’écran 2017-06-20 à 10.17.47.png

           

          HTH

           

          Loic

          Ozalto | Productivity Oriented - Loïc Aigon

          • 2. Re: Array of tables all without the last
            Luca_from_italy Level 1

            ok Loic, tank you for reply,

            Thanks for the answer, but it's not the right one, I did not explain my problem well.
            I have a catalog with 200 pages, 1 table of 2-3 lines per page and 4 columns.
            I have a table that contains the data from the catalog tables, which I use to update the prices.
            The update table also contains new articles not listed in the catalog.
            My script needs to update prices on the catalog, and delete updated articles from the upgrade table, leaving only new articles at the end of the script.

            When I create the var myRows, I create an array that contains all the tables, including the update, and when the comparison loop finds the match, it replaces. After the replacement makes the deletion of var myRowsNew, but being the upgrade table within the myRows array, I also delete all new items.
            Place the script.

            aggiorna();

             

            function aggiorna()

            {   

            if (app.selection.length != 1) 

                 alert ("Selezionare la tabella di aggiornamento"); 

                 exit(0); 

            table = app.selection[0]; 

            if (table.hasOwnProperty("baseline")) 

                 table = table.parent; 

            if (table.constructor.name == "Cell") 

                 table = table.parent; 

            if (table.constructor.name == "Row") 

                 table = table.parent; 

            if (table.constructor.name != "Table") 

                 alert ("Attenzione ! Selezionare con lo strumento testo"); 

                 exit(0); 

             

                //alert ("Table Index: "+table.index+"\nTable Unique ID: "+table.id); 

                var Id=table.id;  //variabile tablla di aggionamento*/

                //var last=Id-1;

                var myDoc = app.activeDocument;

                var myRows=myDoc.stories.everyItem().tables.everyItem().rows.everyItem().getElements();   

                var myRowsNew=myDoc.stories.everyItem().tables.itemByID(Id).rows.everyItem().getElements();

            Outer:   

            for(r=0; r<myRows.length; r++)

            {   

                var cod=myRows[r].cells[0].contents.replace(/ /g, '');

                var des=myRows[r].cells[1].contents;

                var val=myRows[r].cells[2].contents;

                var prz=myRows[r].cells[3].contents;

            Inner:

              for(t=0; t< myRowsNew.length; t++)

              {   

                var codNew=myRowsNew[t].cells[0].contents.replace(/ /g, '');

                var desNew=myRowsNew[t].cells[1].contents;

                var valNew=myRowsNew[t].cells[2].contents;

                var przNew=myRowsNew[t].cells[3].contents;   

                if(cod==codNew)

                    {       

                        try

                        {

                         myRows[r].cells[1].contents =myRowsNew[t].cells[1].contents;

                         myRows[r].cells[2].contents =myRowsNew[t].cells[2].contents;

                         myRows[r].cells[3].contents =myRowsNew[t].cells[3].contents;

                         myRowsNew[t].cells[0].contents="";   // queste 4 righe servono per cancellare i campi della tabella aggiornati

                         //myRowsNew[t].cells[1].contents="";

                         //myRowsNew[t].cells[2].contents="";

                         //myRowsNew[t].cells[3].contents="";

                        }

                        catch(e)

                        {

                        }

                      break Inner;

                    }

                    else

                    {

                     continue Inner;

                    }

                       

              } 

            }

            }