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

Select multiple text frames, find the tables therein

Participant ,
Aug 07, 2019 Aug 07, 2019

I'm trying to script a pretty involved operation on multiple, selected text frames (but not all text frames in the doc), and so I'm taking it step by step. The question I'll ask for now is just the first part and I have been unable to find a script or script discussion that really addresses what I want to do. (I have found lots of documentation on how to get 1 table, or ALL the doc's tables... but that's not what I'm looking for....)

How can I select multiple text frames, some of which have a table and some that don't have a table, and gather up just the tables and put them in an array? So that I can work with just those table objects further?

Thanks for any suggestions or tips to get me going down the right path.

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

Community Expert , Aug 07, 2019 Aug 07, 2019

Hi Andy,

You could try the following with selection of some textframes on the document run the following code

var tb = []          //This is the array that will contain the tables within the selected textframes

for(var a = 0; a< app.selection.length; a++)

{

    if("tables" in app.selection && app.selection.tables.length)

          tb.push(app.selection.tables.everyItem())

}

P.S. :- This will just find the first level tables and not nested tables

-Manan

Translate
Community Expert ,
Aug 07, 2019 Aug 07, 2019

Hi Andy,

You could try the following with selection of some textframes on the document run the following code

var tb = []          //This is the array that will contain the tables within the selected textframes

for(var a = 0; a< app.selection.length; a++)

{

    if("tables" in app.selection && app.selection.tables.length)

          tb.push(app.selection.tables.everyItem())

}

P.S. :- This will just find the first level tables and not nested tables

-Manan

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 ,
Aug 07, 2019 Aug 07, 2019

For obtaining table within tables we could use the text search. Sample code mentioned below

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.findWhat = "<0016>";

var tb = []

try{

    for(var a = 0; a< app.selection.length; a++)

    {

          var f = app.selection.findText()

          for(var i = 0; i < f.length; i++)

              tb.push(f.tables.everyItem());

    }

}catch(e){}

app.findTextPreferences = app.changeTextPreferences = null;

-Manan

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
Participant ,
Aug 09, 2019 Aug 09, 2019

Thank you Manan! I will give these a try and let you know how they work.

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
Enthusiast ,
Dec 10, 2019 Dec 10, 2019
LATEST

"<0016>" a number meaning table? Are there more of these magic numbers?

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
Participant ,
Aug 09, 2019 Aug 09, 2019

Manan, this works as I requested. I now have a variable with my table objects. Thanks! (And now on to figuring out how to do with code what I want to do with those tables )

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