16 Replies Latest reply on Apr 11, 2013 7:42 AM by Vamitul

    columns.redistribute

    Vamitul Level 4

      How does one use it?? i want to "distribute evenly" all the columns in all the tables in my story. Somehow i can't get it to work:

       

      myStory.tables.everyItem().columns[0].redistribute(HorizontalOrVertical.HORIZONTAL) doesn't seem to work.

        • 1. Re: columns.redistribute
          -hans- Level 4

          Hi,

          I don't own cs6 (so I can't test it) but redistribute is described as a method for a range of columns.

          • 2. Re: columns.redistribute
            Vamitul Level 4

            it's on CS5, and ... i'm lost.. it's a column method, but that's about as far as i can get with it..

            • 3. Re: columns.redistribute
              Trevorׅ Adobe Community Professional

              myTable.columns[0].redistribute(HorizontalOrVertical.VERTICAL,myTable.rows[0])

              Is the basic format

              Trevor

              1 person found this helpful
              • 4. Re: columns.redistribute
                Vamitul Level 4

                rows[0]? how does that makes any sense?

                anyway, that means i got no way of using everyItem.

                • 5. Re: columns.redistribute
                  Trevorׅ Adobe Community Professional

                  Vamitul

                   

                  rows[0]? how does that makes any sense? Nop, see http://forums.adobe.com/message/4193947#4193947

                  anyway, that means i got no way of using everyItem. Where's you imagination Today?

                   

                  Something like


                  d = app.documents[0];
                  myTable = d.stories.everyItem().tables.everyItem();
                  t = d.stories.everyItem().tables[0].getElements();
                  myTable.columns[0].redistribute(HorizontalOrVertical.VERTICAL,t[0].rows[0])
                  

                   

                  Trevor

                  • 6. Re: columns.redistribute
                    Vamitul Level 4

                    i think adobe wrote the code for the "redistribute" method on 1 April, because it makes 0 sense.

                    why on earth is VERTICAL??

                    and why is the range of distributing columns a row?!?!

                    it works, but ??

                     

                    ps. if you don't mind, walk me through your code a bit, because apparenty i'm very slow today (spend 2 hours today tying to debug a script, just to realise that the problem was with the document itself - it seems you can't have a paragraph style group named with the same name a a paragraph style -).

                    so..

                    myTable is a colection of every table in the document

                    t is what? an array containg the first table in the document? what's with the getElements there?

                    so.. redistribute the columns of the tables in the document VERTICALY (that actualy means horizontal), using as "the last Column in the range" (quote from the object reference) the first row of the first table in the document?!?!?

                     

                     

                    please shoot me!!!!

                    • 7. Re: columns.redistribute
                      Trevorׅ Adobe Community Professional

                      I'm off for a sleep, will try to get back tonight

                      ZZZZZzzzzzz

                      • 8. Re: columns.redistribute
                        Laubender Adobe Community Professional & MVP

                        @Vamitul – alternatively you can do the following without redistribute():

                         

                         

                        //Cheap trick without redistribute():
                        
                        //One Table selected:
                        var myTable = app.selection[0];
                        
                        //Expand the width of the table a bit:
                        myTable.width = ++myTable.width;
                        
                        //Shrink it back (in the process all columns will be redistributed evenly in width):
                        myTable.width = --myTable.width;
                        



                        Uwe

                        • 9. Re: columns.redistribute
                          Vamitul Level 4

                          thanks uwe.

                          I usualy don't like to use this kind of tricks because you never know if they will still work in the next version of indesign.

                          Plus, i wanted to distribute all the tables in my story, and i wanted to do it in one line (let's say it was a matter of personal pride...)

                          • 10. Re: columns.redistribute
                            Trevorׅ Adobe Community Professional

                            Hhm, a little bug

                            My above script will fail if t[0] has less columns in it that any of the other tables in the doc.

                            But after a several hundred attempts I found this will work

                            myTables = app.documents[0].stories.everyItem().tables.everyItem();
                            myTables.rows[0].redistribute(HorizontalOrVertical.VERTICAL); // changed from columns[0] to row[0] and got rid of the range
                            

                            That will only fail if any of the tables in the document have only 1 column (so they it can't be redistributed).

                            In such you could forego on your pride and iterate through them.

                             

                            Back to the original script and t[0]

                            The idea was to set the range to the first table row in the document so it would do the lot.

                            Well you might think that the above line is not so clear, but it is a perfect reflection of my understanding on the topic (or lack of understanding)

                             

                            Trevor

                            • 11. Re: columns.redistribute
                              Vamitul Level 4

                              nope.. error: Invalid parameter

                              • 12. Re: columns.redistribute
                                Trevorׅ Adobe Community Professional

                                So you must have a table with only one column in it in the top row.

                                Anyway this should deal with MOST cases and only does a very little bit of write iterating so should still be very quick

                                 

                                 

                                // Script by Trevor  http://forums.adobe.com/message/5225003#5225003
                                app.doScript("main()", ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Table Redistribution");
                                function main()
                                {
                                    var  myOneRowTables = [],
                                            n = 0,
                                            mt = app.documents[0].stories.everyItem().tables.everyItem().getElements(), l = mt.length;
                                            myTables = app.documents[0].stories.everyItem().tables.everyItem();
                                    while (l--) if (mt[l].rows[0].cells.length < 2 && mt[l].rows.length > 1) 
                                        {
                                            myOneRowTables [n++] = mt[l];
                                            mt[l].rows[0].cells[0].split (HorizontalOrVertical.VERTICAL);
                                         }
                                    myTables.rows[0].redistribute(HorizontalOrVertical.VERTICAL); // changed from columns[0] to row[0] and got rid of the range
                                    while (n--) 
                                        {
                                            myOneRowTables[n].rows[0].cells[0].merge (myOneRowTables[n].rows[0].cells[1])
                                            myOneRowTables[n].rows.itemByRange(1,-1).redistribute(HorizontalOrVertical.VERTICAL);
                                        }
                                }
                                
                                • 13. Re: columns.redistribute
                                  Laubender Adobe Community Professional & MVP

                                  @Trevor – I still would like  "shaking the tree" with my method.
                                  That is working in every case:

                                   

                                  //Redistribute all tables without redistribute() method:
                                  
                                  var myTables = app.documents[0].stories.everyItem().tables.everyItem().getElements();
                                  
                                  for(var n=0;n<myTables.length;n++){
                                  
                                      //Expand the width of the table a bit:
                                      myTables[n].width = ++myTables[n].width;
                                  
                                      //Shrink it back (in the process all columns will be redistributed evenly in width):
                                      myTables[n].width = --myTables[n].width;
                                  
                                      };
                                  

                                   

                                   

                                  Uwe

                                  • 14. Re: columns.redistribute
                                    Trevorׅ Adobe Community Professional

                                    I took out an accidentally left in line from the above script

                                    • 15. Re: columns.redistribute
                                      Trevorׅ Adobe Community Professional

                                      Uwe, I agree with you that you method is a lot safer and wouldn't be concered what's going to be with CS12.

                                      So here's the compromise see the catch at the bottom.

                                      Safe and Swift (I think)

                                       

                                      // Script by Trevor  http://forums.adobe.com/message/5225003#5225003
                                      app.doScript("main()", ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Table Redistribution");
                                      function main()
                                      {
                                          var  myOneRowTables = [],
                                                  n = 0,
                                                  mt = app.documents[0].stories.everyItem().tables.everyItem().getElements(), l = mt.length;
                                                  myTables = app.documents[0].stories.everyItem().tables.everyItem();
                                          while (l--) if (mt[l].rows[0].cells.length < 2 && mt[l].rows.length > 1) 
                                              {
                                                  myOneRowTables [n++] = mt[l];
                                                  mt[l].rows[0].cells[0].split (HorizontalOrVertical.VERTICAL);
                                               }
                                          myTables.rows[0].redistribute(HorizontalOrVertical.VERTICAL);
                                          while (n--) 
                                              {
                                                  myOneRowTables[n].rows[0].cells[0].merge (myOneRowTables[n].rows[0].cells[1])
                                                  try {myOneRowTables[n].rows.itemByRange(1,-1).redistribute(HorizontalOrVertical.VERTICAL);};
                                                  catch (bug) {myOneRowTables[n].width  = ++myOneRowTables[n].width; myOneRowTables[n].width  = --myOneRowTables[n].width;};
                                              }
                                      }
                                      

                                       

                                      I could find any fail cases with this one.

                                      • 16. Re: columns.redistribute
                                        Vamitul Level 4

                                        I hope you guys know i'we 'fixed' the problem about 3 versions of my script ago (that means this morning... any more revisions and i'll go completly nuts), using Uwe's hack.

                                        I guess if it works i shoudn't complain, but this is by far the largest automation project i'we ever done (getting close to 80000 lines of code so far) and getting stuck on something as simple as this got me realy pissed. I fell is just one hack too many.

                                         

                                        Anyway, thank you all. I got to say that this forum is one of the awesomest communities ever.