17 Replies Latest reply: Apr 25, 2013 4:57 PM by Jean-Claude Tremblay RSS

    Question about tables – alternating fills

    Paul Stedman Community Member

      Apologies, but I new to the world of Tables and, as an exercise only, I am trying to create following:

       

       

      I have a to create a table 21 columns wide (they're very narrow) and nine rows deep

      I want theTOP ROW ONLY to have an alternating fill of 50% black; the first column being white then 50%; then white and so on.

      Producing the alternating fill is (obviously) very easy, but I am struggling to limit it to the top row only.

       

       

      Can anyone advise on the best approach

        • 1. Re: Question about tables – alternating fills
          [Jongware] MVP

          There is no built-in function for this, so the best approach is to do it manually.

           

          (Second best would be a script.)

          • 2. Re: Question about tables – alternating fills
            [Jongware] MVP

            .. a Javascript (save as "AlternatingFills.jsx" in your Scripts folder). As easy as this:

             

            table = app.selection[0];

            if (table.hasOwnProperty("baseline")) table = table.parent;

            if (table instanceof Cell) table = table.parent;

            if (table instanceof Column) table = table.parent;

            if (table instanceof Row) table = table.parent;

            if (table instanceof Table)

            {

            // Top row

            r = table.rows[0];

            // White swatch (I assume you mean 'Paper' or 'None' with that)

            n = app.activeDocument.swatches.item("None");

            // Black swatch

            b = app.activeDocument.swatches.item("Black");

            // Apply to each cell

            for (c=0; c<r.cells.length; c++)

            {

              // Evens set to white, Odds 50% black

              if (c & 1)

              r.cells[c].properties = { fillColor:b,fillTint:50 };

              else

              r.cells[c].fillColor = n;

            }

            } else

            alert ("Yeah, come to think of it you were actually nowhere near a table, werentya?");

             

            (This is actually fairly straightforward.)

            • 3. Re: Question about tables – alternating fills
              Jean-Claude Tremblay UGM-MVPs

              Nice script again [jongware]...

              Do you have one that will do alternate 3 rows colors. The build in Table Fill features allow only alternating two rows. I need to alternate 3 colors...

               

              JC

              • 4. Re: Question about tables – alternating fills
                [Jongware] MVP

                Hmmm ... no chance of getting this into a feature request for CS7 ;-)

                 

                Hold on a mo' ...

                • 5. Re: Question about tables – alternating fills
                  lilia@ Community Member

                  i'm not a huge table user... but i have played with it a bit...

                  Couldn't it just be as simple as assigning the top row to 'Header'?

                  • 6. Re: Question about tables – alternating fills
                    Jean-Claude Tremblay UGM-MVPs

                    If only the first row would be part of the repeat, yes this can be done. But if you need to repeat the 3 colors again and again, no the table feature does not allow you this.

                    • 7. Re: Question about tables – alternating fills
                      [Jongware] MVP

                      Here you are. It isn't limited to just three swatches OR fills -- make it as many as you like. To have additional fun, you can define a different number of tints, so you get pseudo-random background fills. If you want all of your swatches in full, you just have to define one single fill tint: 100% (as this will 'loop' over all rows as well).

                       

                      The script is rigged to skip over table headers and footers, it will colour in only the table body range.

                       

                      app.doScript(function() {
                        // Put Swatch names in here, many as you like:
                        var rowFills = [
                          "Blue",
                          "None",
                          "Black"
                        ];
                        // Put Percentages in here, again many as you like:
                        var rowTints = [
                          50,
                          0,
                          25
                        ];
                      
                        table = app.selection[0];
                        if (table.hasOwnProperty("baseline")) table = table.parent;
                        if (table instanceof Cell) table = table.parent;
                        if (table instanceof Column) table = table.parent;
                        if (table instanceof Row) table = table.parent;
                        if (table instanceof Table)
                        {
                          var startAt = table.headerRowCount;
                          var numRows = table.rows.length-startAt-table.footerRowCount;
                          for (r=0; r<numRows; r++)
                          {
                            table.rows[startAt+r].fillColor = app.activeDocument.swatches.item(rowFills[r % rowFills.length]);
                            table.rows[startAt+r].fillTint = rowTints[r % rowTints.length];
                          }
                        } else
                        {
                          alert ("Yeah, come to think of it you were actually nowhere near a table, werentya?");
                          exit();
                        }
                      }, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Alternate Table Fills");
                      

                       

                      Message was edited by: [Jongware] Lots of forum downtime lately, but it seems *not* to fix the still broken cannot-assign-code bug :(

                      • 8. Re: Question about tables – alternating fills
                        Jean-Claude Tremblay UGM-MVPs

                        Jongware, that is just fantastic... will provide to be usefull a lot.

                         

                        Thanks!

                        • 9. Re: Question about tables – alternating fills
                          sebdea Community Member

                          Hi,

                           

                          I tried to use your script. However, after I copied the script text I opened Apple Script Editor and for some reasons I cannot Compile it. I get an error: Syntax Error, Expected expression, property or key form, etc. but found unknown token.

                           

                          Not to mention I cannot save it as *.jsx file.

                           

                          Please take into account that I am never write or compile scripts. Using them, yes. So, maybe it is something I am doing wrong.

                           

                          lso I am on a MAC with InDesign CS6 if any of these will make a difference.

                           

                          Kind regards,

                          Sebastian

                          • 10. Re: Question about tables – alternating fills
                            Peter Spier ACP/MVPs

                            Javascript is not applescript, and does not require compiling.

                             

                            Paste the code into a plain text editor (like text edit) and save as plain text, but change the extension to .jsx and it should work.

                            • 11. Re: Question about tables – alternating fills
                              sebdea Community Member

                              Actually it is not working. I copied the text of the script, inserted into Adobe Extended Script Tool, saved it as *.jsx and added into InDesign User Scripts.

                               

                              I create a table and ran the script and it returned an error

                               

                               

                               

                              It might be missing something in the script.

                               

                              Here it is what I took from that post:

                               

                              ***********************

                              app.doScript(function() {

                                // Put Swatch names in here, many as you like:

                                var rowFills = [

                                  "Blue",

                                  "None",

                                  "Black"

                                ];

                                // Put Percentages in here, again many as you like:

                                var rowTints = [

                                  50,

                                  0,

                                  25

                                ];

                               

                                table = app.selection[0];

                                if (table.hasOwnProperty("baseline")) table = table.parent;

                                if (table instanceof Cell) table = table.parent;

                                if (table instanceof Column) table = table.parent;

                                if (table instanceof Row) table = table.parent;

                                if (table instanceof Table)

                                {

                                  var startAt = table.headerRowCount;

                                  var numRows = table.rows.length-startAt-table.footerRowCount;

                                  for (r=0; r<numRows; r++)

                                  {

                                    table.rows[startAt+r].fillColor = app.activeDocument.swatches.item(rowFills[r % rowFills.length]);

                                    table.rows[startAt+r].fillTint = rowTints[r % rowTints.length];

                                  }

                                } else

                                {

                                  alert ("Yeah, come to think of it you were actually nowhere near a table, werentya?");

                                  exit();

                                }

                              }, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Alternate Table Fills");

                              **********************

                               

                              Anyway, thank you for idea.

                              • 12. Re: Question about tables – alternating fills
                                Peter Spier ACP/MVPs

                                Please delete your personal info when replying by email.

                                 

                                What version of ID are you using? What was the error message you received?

                                • 13. Re: Question about tables – alternating fills
                                  sebdea Community Member

                                  It was a signature. I will reply within Adobe Forum.

                                   

                                  I am using InDesign CS6.

                                   

                                  The error is as follows:

                                   

                                  Screen Shot 2013-02-03 at 2.10.41 PM.jpg

                                  • 14. Re: Question about tables – alternating fills
                                    Peter Spier ACP/MVPs

                                    We'll need to wait for Jongware, I think. this is beyond my scripting ability, and it may be that it needs to run with an interpreter for a particular version.

                                    • 15. Re: Question about tables – alternating fills
                                      [Jongware] MVP

                                      First thing to check is your list of color names. My script has "Blue", "None", and "Black". The last two are by default in InDesign, but "Blue" is not.

                                      The script only works if you actually *have* a Swatch called "Blue".

                                       

                                      If you changed the color list, make sure each of the color names match actual swatch names.

                                      • 16. Re: Question about tables – alternating fills
                                        sebdea Community Member

                                        I did not have a chance to get back and thank you for your big help. I am sorry and please accept my apologizes. I appreciate your help and that you spent time answering to this post.

                                         

                                        I wish you all the best.

                                         

                                        Sincerely yours,

                                        Sebastian

                                        • 17. Re: Question about tables – alternating fills
                                          Jean-Claude Tremblay UGM-MVPs

                                          Hi Jongware,

                                           

                                          You script have been very usefull so far, but now I need it to apply the alternates color to ONLY the selected rows and not the entire table. I have absolutely no clue how to modify the script.

                                           

                                          Can you help again?

                                           

                                          Thanks!