6 Replies Latest reply on Sep 2, 2014 10:36 PM by VeluVK

    Distribute column

    VeluVK Level 1

      Hi,

       

      Anyone having script for the below requirement:

       

      For all tables, from second column onwards distribute the column width into "6p" (first column width variable). and also tables need to be fit (100%) with in the text margin.

      distribute.JPG

       

       

      Regards,

      Velu

        • 1. Re: Distribute column
          Chinnadk Level 4

          Hi Velu,

           

          Try this,

           

          var doc = app.activeDocument;
          doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.picas;
          doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.picas;
          for(var i =app.selection[0].columns.length-1;i>0;i--)
          {
                  app.selection[0].columns[i].width = "6P";
              }
          var w = doc.documentPreferences.pageWidth,
              _left = doc.marginPreferences.left,
              _right = doc.marginPreferences.right;
          try
          {
                  app.selection[0].columns[0].width  =  (w - _left - _right) - (app.selection[0].columns.length-1)*6;
              }
          catch(e)
          {
                  alert("Table width exeeds the length of the text area!")
              }
          
          

           

          Regards,

          Chinna

          • 2. Re: Distribute column
            VeluVK Level 1

            Hi Chinna,

             

            Please find below error.

             

            distribute.JPG

             

            Regards,

            Velu

            • 3. Re: Distribute column
              Chinnadk Level 4

              Hi Velu,

               

              The table must be selected instead of putting a cursor into it.

               

              Regards,

              Chinna

              • 4. Re: Distribute column
                VeluVK Level 1

                Hi Chinna,

                 

                When i select table the script working, but the table width exceed out of the margin.

                 

                I need the script for all the tables. The documents contains 200+ tables.

                 

                untitled.JPG

                 

                Regards,

                Velu

                • 5. Re: Re: Distribute column
                  Chinnadk Level 4

                  Try now, it will run on all the tables.

                   

                  var doc = app.activeDocument,
                      _tables = doc.stories.everyItem().tables.everyItem().getElements(),
                      w = doc.documentPreferences.pageWidth;
                  
                  doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.picas;
                  doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.picas;
                  
                  for(var i =0;i<_tables.length;i++)
                  {
                          for(var j =_tables[i].columns.length-1;j>0;j--)
                          {
                                  _tables[i].columns[j].width = "6P";
                              }
                          var _left = _tables[i].parent.parentPage.marginPreferences.left,
                              _right = _tables[i].parent.parentPage.marginPreferences.right;
                          try
                          {
                                  _tables[i].columns[0].width  =  (w - (_left + _right)) - (_tables[i].columns.length-1)*6 ;
                              }
                          catch(e)
                          {
                                  alert("Table width exeeds the length of the text area!")
                              }        
                      }
                  

                   

                   

                  Regards,

                  Chinna

                  • 6. Re: Distribute column
                    VeluVK Level 1

                    Hi Chinna,

                     

                    Thank you so much, Script working perfect.

                     

                     

                    Regards,

                    Velumani