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

Changing table direction - script

Community Beginner ,
Aug 18, 2014 Aug 18, 2014

Hello all,

I have a series of large Arabic documents where I need to flip the table direction to RTL. I've cobbled together the following:

var a = app.activeDocument.textFrames.everyItem().tables.everyItem().getElements();

for (var i=a.length-1; i > 0; i--){

a.tableDirection = TableDirectionOptions.RIGHT_TO_LEFT_DIRECTION;

}

It seems to work but doesn't catch every table - what have I left out?

TOPICS
Scripting
834
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

correct answers 1 Correct answer

Deleted User
Aug 18, 2014 Aug 18, 2014

And shouldn't it be "i >= 0"?


Translate
Guest
Aug 18, 2014 Aug 18, 2014

Hi,

maybe it is worth a try to use "stories" instead of "textFrames"?

var a = app.activeDocument.stories.everyItem().tables.everyItem().getElements();

BR

Jan

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 Beginner ,
Aug 18, 2014 Aug 18, 2014

Hi Jan

Thanks - I did try this but "stories" still does not pick up every 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
Guest
Aug 18, 2014 Aug 18, 2014

And shouldn't it be "i >= 0"?


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 Beginner ,
Aug 18, 2014 Aug 18, 2014

Ha, thank you! How elementary

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
Guest
Aug 18, 2014 Aug 18, 2014

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
People's Champ ,
Aug 18, 2014 Aug 18, 2014

it should be

i >= 0

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
Mentor ,
Aug 18, 2014 Aug 18, 2014

Please try without the loop. If you assign a value to everyItem().someProperty, it should modify each referenced object.

app.activeDocument.stories.everyItem().tables.everyItem().tableDirection = TableDirectionOptions.RIGHT_TO_LEFT_DIRECTION;

Dirk

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
Mentor ,
Aug 18, 2014 Aug 18, 2014

Hi Dirk

For the nested tables one would add

app.findTextPreferences.findWhat = "\x16";

then loop though the results and change direction as required


Trevor

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
Mentor ,
Aug 18, 2014 Aug 18, 2014

Hi Trevor,

thanks for bringing up nested tables. Do you mean tables nested in table cells? That would be:

app.activeDocument.stories.everyItem().tables.everyItem().tableDirection = TableDirectionOptions.RIGHT_TO_LEFT_DIRECTION;

app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().tables.everyItem().tableDirection = TableDirectionOptions.RIGHT_TO_LEFT_DIRECTION;

Probably it is a good idea to add some try/catch if any of the expressions yields no hits, e.g. the doc has no tables.

Dirk

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
Mentor ,
Aug 18, 2014 Aug 18, 2014

Hi Dirk

Yes, but if you want to catch those really common tables nested in cells of tables nested in cells etc. then

See https://forums.adobe.com/message/6087936#6087936

Trevor

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
Mentor ,
Aug 18, 2014 Aug 18, 2014
LATEST

Hi Dirk

This will get all the nested tables regardless of their depth, although I am not certain whether this or the Grep method would be faster for very lager documents with large amounts of nested levels.

var doc = app.activeDocument, t;

(t = doc.stories.everyItem().tables.everyItem()).tableDirection = TableDirectionOptions.RIGHT_TO_LEFT_DIRECTION;

while (t.cells.length) (t = t.cells.everyItem ().tables.everyItem ()).tableDirection = TableDirectionOptions.RIGHT_TO_LEFT_DIRECTION;

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