Select a table after creation through a script

Community Beginner ,
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

80

Likes

translate

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

Adobe Community Professional , 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...

Likes

translate

Translate

Translate
Adobe Community Professional ,
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. 

Likes

translate

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 Beginner ,
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 !

 

 

Likes

translate

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

Copy link to clipboard

Copied

Correct, you can use any string you want. 

Likes

translate

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