• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to select an InDesign table using Javascript

Explorer ,
Apr 02, 2020 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/]

TOPICS
Feature request

Views

1.3K

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
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 02, 2020 Apr 02, 2020

Try

app.select(allTables[aTable])

 

-Manan

Votes

Translate

Translate
Community Expert ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

Try

app.select(allTables[aTable])

 

-Manan

Votes

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
community guidelines
Explorer ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

Thank you Manan.

 

That works!

 

m.

Votes

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
community guidelines
Guru ,
Apr 02, 2020 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();
		}
	}
}

 

Votes

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
community guidelines
Explorer ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

LATEST

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.

Votes

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
community guidelines