Copy link to clipboard
Copied
Dear all,
Greetings....
The below script is working perfectly in indesign CS3 to apply the table and cell style. But in indesign CS4 is showing runtime error. Kindly help me on this........
var myTable = app.activeDocument.stories.everyItem().tables;
for (var n=0; n < myTable.length; n++)
{
myTable
.appliedTableStyle = "Table Style 1"; myTable
.cells.everyItem().appliedCellStyle = app.activeDocument.cellStyles.item("[None]"); myTable
.cells.everyItem().clearCellStyleOverrides (true); alert(myTable
.rows.length); for (var a = 1; a < myTable
.rows.length - 2; ++a) {
myTable
.rows.cells.everyItem().appliedCellStyle = "T body"; alert(a);
}
myTable
.rows[0].cells.everyItem().appliedCellStyle = "T col hd";//First Row myTable
.rows[-1].cells.everyItem().appliedCellStyle = "T body bot";//Last Row }
Thanks
Karthik
Hi Karthik,
Please try the below JS Code and revert.
...var myTable = app.activeDocument.stories.everyItem().tables;
for (var n=0; n < myTable.length; n++){
//~ myTable
.appliedTableStyle = "Table Style 1"; //~ myTable
.cells.everyItem().appliedCellStyle = app.activeDocument.cellStyles.item("[None]"); //~ myTable
.cells.everyItem().clearCellStyleOverrides (true); // Please check the table cell styles name is correct or not?
var myActiveTable = myTable
; myActiveTable.rows.itemByRange
Copy link to clipboard
Copied
Hi M Karthik,
Your code JS code is working perfecet on InDesign CS4 platform Mac OS 10.5.6. Can you please post the runtime error snapshot. And also can you do this please clear/delete the InDesign Preferences after that try again once.
thx
csm_phil
Copy link to clipboard
Copied
Hi
I am working on Windox XP CS4. As instructed, i have placed the runtime error screenshot image for yours reference....
Thanks
Karthik
Copy link to clipboard
Copied
can't help you with the script you have, but have seen an alternative script which may help. written by martin fischer. go to:
Copy link to clipboard
Copied
Is this for CS4 only? I try in CS5 (win7) and get nothing but errors.
i just want to apply a style over rides and a simple table styles to all my tables, but i can't find anything that works. PLEASE HELP.
Copy link to clipboard
Copied
If you don't tell us what the errors are, we cannot help you.
Copy link to clipboard
Copied
You must attach screenshots using the web interface, you cannot do so via email.
You should probably go to the web site and edit your posts, they are inscrutable, and also contain extraneous quoted information from the previous posts.
There's not enough information about your problem to help you.
It sounds like it is detailed enough to merit a thread of its own.
Copy link to clipboard
Copied
Hi John,
I'm at a loss as to how come the script works on one system but not mine(CS5 win7).
What are the coloured letters near the end of each of the last 3 lines of code?
What are the variables that I need to load with my table style name?
thanks
FYi, i've begun the brutal task of manual formatting, the deadline is looming.
Copy link to clipboard
Copied
Robert:
Your error message refers to a string on line 2, "RB_Base_Table.length", which does not appear on line 2 of any of the versions of the script in this thread. Instead they have "myTable." Did you alter the script?
If so, why did you do so? As written, it operates on all tables in the document.
The colored letters are syntax highlighting intended to make it easier to read and understand the script. You can ignore the colors and simply cut and paste thes script verbatim.
Copy link to clipboard
Copied
This came up when i ran the unaltered scipt on a 1 page doc (CS5 win7) containing a 3 col by 7 row table.
Copy link to clipboard
Copied
I'm not sure what you're expecting. Line 9 of the script sets the style of some rows to a style named "TB."
I'm sorry for saying that the script needed to run unaltered. Clearly that's not the case. You do need to change the styles that the script uses (in double-quoted strings) into styles that are applicable to your situation. Even then the script is a bit specific...
Copy link to clipboard
Copied
FANTASTIC, thank you John, the cell style now applies.
what xyntax should i use for appling a table style?
thanks
Copy link to clipboard
Copied
what syntax should i use for appling a table style?
myActiveTable.appliedTableStyle="Whatever";
Copy link to clipboard
Copied
Thanks John,
I found a sample that sort of works;
myTable
What does the
My latest issue is that cell and table styles over-rides need to also be applied in this script.
Though I'm half through my current 'table fest' project, it still behooves me to run a good script to finish the second half of my book in a fraction of the time that the first half took. Hopefully a good script will also alow me to have the weekend off after week of 10 and 12 hour daze.
Copy link to clipboard
Copied
myTable
.appliedTableStyle = "RB_Base_Table"; What does the
mean?
It refers to the nth table, where n is a variable. Because it is a for loop, its contents execute once for every table.
In this case, "myTable
My latest issue is that cell and table styles over-rides need to also be applied in this script.
It is not clear what you are asking for, if anything.
Copy link to clipboard
Copied
Thanks John,
sorry about the ambigiuity of my request.
What I need is the syntax to clear overrides for paragraphs, cell and table styles, Please.
thanks
Copy link to clipboard
Copied
Have you looked through the documentation, or the object model at http://jongware.mit.edu, or searched on the scripting forum for "clear overrides"?
It's really expected that you put a bit of effort into figuring this out yourself.
For a table, you can use myActiveTable.clearTableStyleOverrides();.
For cells, similarly, instead of (or in addition) to setting .appliedCellStyle, you can also call .clearCellOverrides().
For paragraph styles, it's a bit more complicated since you don't deal with paragraph attributes anywhere.
I suppose you can likely use cells.everyItem().paragraphs.everyItem().clearOverrides().
Copy link to clipboard
Copied
Thank-you John,
And yes, initially, i did put a lot effort into it.
However, debugging the scripts that i did find was eating away at my production time, which was totally stressing out my manager.
I’m sorry for the bother that i’ve caused you, but your efforts have been tremendously appreciated!
Once again, thank-you John.
Robert Bourassa
Senior Production Artist
Copy link to clipboard
Copied
Hi Karthik,
Please try the below JS Code and revert.
var myTable = app.activeDocument.stories.everyItem().tables;
for (var n=0; n < myTable.length; n++){
//~ myTable
.appliedTableStyle = "Table Style 1"; //~ myTable
.cells.everyItem().appliedCellStyle = app.activeDocument.cellStyles.item("[None]"); //~ myTable
.cells.everyItem().clearCellStyleOverrides (true); // Please check the table cell styles name is correct or not?
var myActiveTable = myTable
; myActiveTable.rows.itemByRange(0,-2).cells.everyItem().appliedCellStyle = "TB";
myActiveTable.rows[0].cells.everyItem().appliedCellStyle = "TCH";//First Row
myActiveTable.rows.itemByRange(-2,-1).cells.everyItem().appliedCellStyle = "TBB";//Last Row
}
the above js code output is like this snapshot.
thx
csm_phil
Copy link to clipboard
Copied
Thanks csm_phil. you have done a great job for me. Thanks a lot..................