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

find tables and apply table-style to all

Explorer ,
Feb 13, 2023 Feb 13, 2023

Dear all! Is there a possibility to find all tables (all table-text has a special paragraph-style "TableText") and apply tablestyle to all in 1 go? thank you thank you thank you 🙂

TOPICS
Print , Type
950
Translate
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
Community Expert ,
Feb 13, 2023 Feb 13, 2023

It'll have to be a script:

 

style = app.documents[0].tableStyles.item('TableText');
tables = app.documents[0].stories.everyItem().tables.everyItem().getElements();
for (i = 0; i < tables.length; i++) {
  tables[i].appliedTableStyle = style;
}

P

Translate
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 ,
Feb 13, 2023 Feb 13, 2023

Dear Peter, that looks promiing but unfortunately I get an error:

Screenshot 2023-02-13 at 15.56.17.png

Translate
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
Community Expert ,
Feb 13, 2023 Feb 13, 2023

Sorry, Caroline, I should have read your post more carefully. The tables you're after are in a paragraph style TableText, and you want to apply a table style. You didn't say what the name of the table style is, in the updated script, below, I assumed TableText (same name as the paragraph style). If you use a different name, replace TableText in the script's first line with the name you use.

style = app.documents[0].tableStyles.item('TableText');
tables = app.documents[0].stories.everyItem().tables.everyItem().getElements();
for (i = 0; i < tables.length; i++) {
  if (tables[i].storyOffset.appliedParagraphStyle.name == 'TableText') {
    tables[i].appliedTableStyle = style;
  }
}

 

Translate
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 ,
Feb 13, 2023 Feb 13, 2023

Oh dear, it seems I make a mistake again. My Table-style is named My_Table, my paragraph-style TableText. But still i get an error.Complicated matter these scripts... Thanks for your time and patience!

Screenshot 2023-02-13 at 19.13.08.png

Translate
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
Community Expert ,
Feb 13, 2023 Feb 13, 2023

The name of the table style should be changed in the script;

style = app.documents[0].tableStyles.item('My_Table');
tables = app.documents[0].stories.everyItem().tables.everyItem().getElements();
for (i = 0; i < tables.length; i++) {
  if (tables[i].storyOffset.appliedParagraphStyle.name == 'TableText') {
    tables[i].appliedTableStyle = style;
  }
}
Translate
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 ,
Feb 13, 2023 Feb 13, 2023

Yes, I did that but still got the error...

 

Translate
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
Community Expert ,
Feb 13, 2023 Feb 13, 2023

Could you send your document to pkahrel@gmail.com?

Translate
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 ,
Feb 13, 2023 Feb 13, 2023

Dear Peter, that is so very kind of you!
And guess what?!
While making the e-mail to you I discoverd what went wrong! I corrected the script in Indesign version 2022 instead of Indesign 2023.... AAAGGHHH.... so very very stupid.
The good news: IT WORKS!!!
While working on this, I'm thinking:
I made this query now in 2 steps. First I searced for tables and changed the paragraph style in every table

app.activeDocument.stories.everyItem().tables.everyItem().changeText();

(thanks to brianp311) and then I used your script to change said paragraphe-style to table-style.

Can that be done in 1 script instead of 2?

 

Translate
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
Community Expert ,
Feb 13, 2023 Feb 13, 2023
LATEST

Sure. Since you want to appy the table style to all tables, my script can be reduced to a single line, which comes after Brian's line:

app.activeDocument.stories.everyItem().tables.everyItem().changeText();

app.activeDocument.stories.everyItem()
  .tables.everyItem()
  .appliedTableStyle = app.activeDocument.tableStyles.item('My_Table');

 

Translate
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