Copy link to clipboard
Copied
Hi. I know how I would do this with VBA, but I can't seem to find the syntax in Javascript and would be grateful for any help.
I have a document with more than 500 tables, all of which need to have their columns reduced to their narrowist width. I'm using Marc Autret and Kasyan Servetsky's script, "Table Cell Width Minimizer," but selecting every table and then double-clicking the script takes forever. I would like to write a simple Javascript to run the Autret/Servetsky script on every table. The problem is that the Autret/Servetsky script requires that the table be selected to execute.
I can create the loop and call the Autret/Servetsky script, but I cannot find a way to automatically select each table. Here's what I have:
allTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
myScript=File("~/Library/Preferences/Adobe InDesign/Version 15.0-ME/en_AE/Scripts/Scripts Panel/Table Cell Width Minimizer.jsx");
for (aTable=0; aTable<allTables.length; aTable++)
{
//Command to select table goes here
app.doScript (myScript);
}
Thanks for any help.
[Moved from Community Help (which is about the forums) to a better forum... Mod]
[To find a forum for your program please start at https://community.adobe.com/]
1 Correct answer
Try
app.select(allTables[aTable])
-Manan
Copy link to clipboard
Copied
Try
app.select(allTables[aTable])
-Manan
Copy link to clipboard
Copied
Thank you Manan.
That works!
m.
Copy link to clipboard
Copied
Your approach is correct:
- loop through every story in the doc
- and then loop through table every in each story
You don't have to select tables by script!
I couldn't find the script you mention, but, I think, you should call the function that processes the table: not the whole script which requires a table to be selected.
function findTable(){
for ( s = myDoc.stories.length-1; s >= 0; s-- ){
for ( t = myDoc.stories[s].tables.length-1; t >= 0; t-- ){
myTable = myDoc.stories[s].tables[t];
doSomethingHere();
}
}
}
Copy link to clipboard
Copied
Thanks! I wondered if you would get the message. I tried Manan's solution first, and it got me where I need to be, but I still appreciate you taking the time to suggest another approach. I can send you the .jsx file if you would like it. In its header, it says, "/* -- updated by Kasyan Servetsky | 17/08/2014 */."
m.

