Highlighted

How to select an InDesign table using Javascript

Explorer ,
Apr 02, 2020

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/]

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

Try

app.select(allTables[aTable])

 

-Manan

TOPICS
Feature request

Views

515

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How to select an InDesign table using Javascript

Explorer ,
Apr 02, 2020

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/]

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

Try

app.select(allTables[aTable])

 

-Manan

TOPICS
Feature request

Views

516

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 02, 2020 0
Adobe Community Professional ,
Apr 02, 2020

Copy link to clipboard

Copied

Try

app.select(allTables[aTable])

 

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 02, 2020 1
Explorer ,
Apr 03, 2020

Copy link to clipboard

Copied

Thank you Manan.

 

That works!

 

m.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 03, 2020 0
Guru ,
Apr 02, 2020

Copy link to clipboard

Copied

Your approach is correct:

  1. loop through every story in the doc
  2. 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();
		}
	}
}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 02, 2020 1
LinusCMH LATEST
Explorer ,
Apr 03, 2020

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 03, 2020 0