Alternating Fills
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Alternating Fills
- This topic has 7 replies, 3 voices, and was last updated 6 years ago by Masood Ahmad.
-
AuthorPosts
-
-
March 2, 2018 at 1:38 pm #102093Masood AhmadParticipant
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 -
March 11, 2018 at 4:45 am #102308Colin FlashmanParticipant
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;
} -
March 11, 2018 at 4:49 am #102312Colin FlashmanParticipant
(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); } } -
March 11, 2018 at 4:51 am #102316Colin FlashmanParticipant
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”;}
-
March 11, 2018 at 10:35 am #102319Masood AhmadParticipant
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;
}
-
March 12, 2018 at 12:17 am #102328Colin FlashmanParticipant
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.
-
March 12, 2018 at 1:23 am #102330Kai RübsamenMember
Colin, well written!
-
March 12, 2018 at 1:25 am #102332Masood AhmadParticipant
THANK YOU !!!!!!!!!!
-
-
AuthorPosts
- You must be logged in to reply to this topic.