Skip to main content
Fred.L
Inspiring
March 11, 2021
Answered

Select a table after creation through a script

  • March 11, 2021
  • 1 reply
  • 566 views

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

This topic has been closed for replies.
Correct answer brian_p_dts

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. 

1 reply

brian_p_dts
Community Expert
brian_p_dtsCommunity ExpertCorrect answer
Community Expert
March 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 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. 

Fred.L
Fred.LAuthor
Inspiring
March 12, 2021

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 !

 

 

brian_p_dts
Community Expert
Community Expert
March 12, 2021

Correct, you can use any string you want.