Skip navigation
Currently Being Moderated

Question about tables – alternating fills

May 9, 2012 1:31 AM

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

 
Replies
  • Currently Being Moderated
    May 9, 2012 2:34 AM   in reply to Paul Stedman

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

     

    (Second best would be a script.)

     
    |
    Mark as:
  • Currently Being Moderated
    May 9, 2012 2:41 AM   in reply to [Jongware]

    .. 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.)

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2012 10:49 AM   in reply to [Jongware]

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2012 2:10 PM   in reply to Jean-Claude Tremblay

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

     

    Hold on a mo' ...

     
    |
    Mark as:
  • lilia@
    196 posts
    Jan 31, 2012
    Currently Being Moderated
    Jun 7, 2012 2:17 PM   in reply to Paul Stedman

    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'?

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2012 2:52 PM   in reply to lilia@

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2012 2:58 PM   in reply to [Jongware]

    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 :(

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2012 3:57 PM   in reply to [Jongware]

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

     

    Thanks!

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 3, 2013 2:09 AM   in reply to [Jongware]

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 3, 2013 3:40 AM   in reply to sebdea

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 3, 2013 4:27 AM   in reply to Peter Spier

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 3, 2013 4:26 AM   in reply to sebdea

    Please delete your personal info when replying by email.

     

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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 3, 2013 4:32 AM   in reply to Peter Spier

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 3, 2013 5:59 AM   in reply to sebdea

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 3, 2013 7:58 AM   in reply to Peter Spier

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 24, 2013 3:36 AM   in reply to [Jongware]

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 25, 2013 4:57 PM   in reply to [Jongware]

    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!


     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points