Alternating Fills

Viewing 7 reply threads
  • Author
    Posts
    • #102093
      Masood Ahmad
      Participant

      Hi, I need a JavaScript to perform the below listed steps:

      Option1:
      1/ Apply the myTableStyle style to the current table. By current table I mean the table with Cursor in it.
      2/ Format the table with Alternate Fills (the existing style do not have the Alternating Fills, I am not supposed to edit it).
      2.1/ First 1 Row : Color: None
      2.2/ Next 1 Row : Color: Black 20%

      Option2:
      3/ Same steps as in Option1.
      3/ Convert the the first row to header of the current table.

      Any help would be much appreciated.

      Thanks in advance.
      Masood

    • #102308
      Colin Flashman
      Participant

      Do you have a script at the moment that you are having difficulty with and you can share with us, or would you like a complete script written? Please understand that writing complete scripts is the lifeblood of javascripters, so asking for a complete script is usually a task that a scripter would be paid for, unless posters reading this request feel benevolent or are after a challenge.

      Jongware wrote a great piece back in the day about tackling tables through scripting: https://creativepro.com/tackling-tables-through-scripting.php

      In his article, it highlights how to select a table that the cursor is in (the first part of your question):

      function checkWhichTable()
      {
      // ensure the user made a selection
      if (app.selection.length != 1)
      return null;
      var currentTable = app.selection[0];
      if (currentTable.hasOwnProperty(“baseline”))
      {
      currentTable = app.selection[0].parent;
      }
      while (currentTable instanceof Cell || currentTable instanceof Row || currentTable instanceof Column)
      currentTable = currentTable.parent;
      if (!(currentTable instanceof Table))
      {
      // No table selected
      return null;
      }
      return currentTable;
      }

    • #102312
      Colin Flashman
      Participant

      (second part of my original answer – forums giving me grief):

      app.doScript(checkUserSelection, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, “Process Table”);

      function checkUserSelection ()
      {
      var a_table = checkWhichTable();
      if (a_table == null)
      {
      if (confirm(“No table selected. Do you want to process all tables?”) == false)
      return;
      allTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
      for (aTable=0; aTable < allTables.length; aTable++) { processTable (allTables[aTable]); } } else { processTable (a_table); } }

    • #102316
      Colin Flashman
      Participant

      third part – having so much trouble with the forum tonight!

      I’ll get you started on the next portion of the script (the part two) but parts 2.1 and 2.2 can be answered by reading Jongware’s article:

      function processTable(table)
      {
      table.appliedTableStyle = “myTableStyle”;

      }

    • #102319
      Masood Ahmad
      Participant

      Thanks Colin for the inputs. I tried it but it seems there’s something missing.

      I think I have ordered the script correctly.
      The script just applies the myTableStyle but didn’t remove the overrides completely.

      Secondly, I need a script to do as:
      1/ Apply the myTableStyle style to the current table. By current table I mean the table with Cursor in it.
      2/ Format the table with Alternate Fills (the existing style do not have the Alternating Fills, I am not supposed to edit it).
      2.1/ First 1 Row : Color: None
      2.2/ Next 1 Row : Color: Black 20%

      And another script to:
      1/ Apply the myTableStyle style to the current table. By current table I mean the table with Cursor in it.
      2/ Format the table with Alternate Fills (the existing style do not have the Alternating Fills, I am not supposed to edit it).
      2.1/ First 1 Row : Color: None
      2.2/ Next 1 Row : Color: Black 20%
      3/ Convert the the first row to header of the current table.


      app.doScript(checkUserSelection, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Process Table");

      function checkUserSelection ()
      {
      var a_table = checkWhichTable();
      if (a_table == null)
      {
      if (confirm("No table selected. Do you want to process all tables?") == false)
      return;
      allTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
      for (aTable=0; aTable < allTables.length; aTable++) { processTable (allTables[aTable]); } } else { processTable (a_table); } }

      function processTable(table)
      {
      table.appliedTableStyle = "Table_Alternating-Fills";
      }

      function checkWhichTable()
      {
      // ensure the user made a selection
      if (app.selection.length != 1)
      return null;
      var currentTable = app.selection[0];
      if (currentTable.hasOwnProperty("baseline"))
      {
      currentTable = app.selection[0].parent;
      }
      while (currentTable instanceof Cell || currentTable instanceof Row || currentTable instanceof Column)
      currentTable = currentTable.parent;
      if (!(currentTable instanceof Table))
      {
      // No table selected
      return null;
      }
      return currentTable;
      }

    • #102328
      Colin Flashman
      Participant

      As my original post says, “Please understand that writing complete scripts is the lifeblood of javascripters, so asking for a complete script is usually a task that a scripter would be paid for”.

      That said, I’m not writing the complete script for you, but instead telling you where the answer lies – in Jongware’s post in InDesignsecrets. Your original post does say “any help would be appreciated”. Jongware’s article will certainly answer your question as well as future table issues.

      I did give you the first parts of the script that are from the article as not only is it in the public domain, it’s on indesignsecrets. Those portions are: to differentiate between every table and the table the cursor is in; and how to apply a table style to the selected table.

    • #102330

      Colin, well written!

    • #102332
      Masood Ahmad
      Participant

      THANK YOU !!!!!!!!!!

Viewing 7 reply threads
  • You must be logged in to reply to this topic.
>