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

Select a table after creation through a script

Participant ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

Hi,

Still learning scripting for Id, I'm facing a probably very basic problem for you guys.

 

I've done a ConvertToText within a script, but I would like to get this new table selected after its creation, for me to keep working on it, using grep expressions for instance.

 

app.selection[0].convertToTable("\t","\t",1);  

 The table is fine, with all the datas in it, but the newly created table becomes unselected.

I feel I have to name it and get it selected through its name, but … well, didn't find how to do it. 😞

 

Thanks for your help

TOPICS
Scripting

Views

312

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 , Mar 11, 2021 Mar 11, 2021

If you look at the DOM API, you will see that convertToTable returns a Table object. That is what is indicated by Table before function name in the API description here: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Text.html#d1e458928__d1e465561

 

As such, you can assign it a variable, or you can even select it.

 

var myTable = app.selection[0].convertToTable("\t","\t",1);
var myFirstRow = myTable.rows[0];
myTable.select();
//etc.

 

You'll find after you script long enough that sel

...

Votes

Translate

Translate
Community Expert ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

If you look at the DOM API, you will see that convertToTable returns a Table object. That is what is indicated by Table before function name in the API description here: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Text.html#d1e458928__d1e465561

 

As such, you can assign it a variable, or you can even select it.

 

var myTable = app.selection[0].convertToTable("\t","\t",1);
var myFirstRow = myTable.rows[0];
myTable.select();
//etc.

 

You'll find after you script long enough that selecting becomes less of a need (though .select() still has its use cases); as long as you have a valid object reference, you can do whatever you want. 

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
Participant ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

Terrific, thank you

 

Going forward, am I right to assume that, since the "columnSeparator" and "rowSeparator" are "string" I could use something different than "\t" for identifying the rows ?

Tabulations are pretty common and could interfere in the process of the table creation. Since I'm dealing with texts from MSWord documents, automatically generated by Smartcat (online translation interface) a tabulation may be sneaking somethere, from time to time.

Anyways, I'll give it a try 😉

Thanks again !

 

 

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
Community Expert ,
Mar 12, 2021 Mar 12, 2021

Copy link to clipboard

Copied

LATEST

Correct, you can use any string you want. 

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