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

Find Tab-delimited Text in a Document/Story, Convert to Table and Clear all Cell Over-rides.

Explorer ,
Apr 09, 2022 Apr 09, 2022

Copy link to clipboard

Copied

Hello

I've been searching in vain for an Indesign Script that will search a given story (or document) find any tab-delimited text (I'm currently finding it using GREP in Find/Change using (^(.+ ){1,3}.+)(\r?(^(.+ ){1,3}.+))+ ) and then convert it into a table.

 

If it could then select all the cells in the table and clear any over-rides that would be great. If I could then choose which Table Style to apply it would be the perfect solution and would save me hours of work.

 

Can anyone help or point me in the right direction?

 

Best regards

 

 

Rob

TOPICS
Scripting

Views

149

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 ,
Apr 09, 2022 Apr 09, 2022

Copy link to clipboard

Copied

Hi @Rob.Wood , if you select a range of tab-delimited text and run this script it will convert the text to a table, apply a table style named "MyTable" and clear any cell overrides. Change MyTable to the name of your style.

 

 

 

 

var doc = app.activeDocument
var ts = "MyTable"
var s=app.activeDocument.selection[0]; 

var t = s.convertToTable ("\t", "\r")
t.appliedTableStyle = doc.tableStyles.itemByName(ts);
var tc = t.cells;
for (var i = 0; i < tc.length; i++){
    tc[i].clearCellStyleOverrides(true)
};   

 

 

 

 

 

Your grep code isn’t working for me in the UI Grep F&C, but this will loop through a search result and do the above to the returned texts. In JS backslashes have to be escaped, e.g. \\r

 

 

 

 

var doc = app.activeDocument
var ts = "MyTable"
var gres = grepFind("(^(.+ ){1,3}.+)(\\r?(^(.+ ){1,3}.+))+ )")
if (gres.length == 0) {
	alert("No text found")
} 

var tc;

for (var i = 0; i < gres.length; i++){
    gres[i].convertToTable ("\t", "\r");
    gres[i].appliedTableStyle = doc.tableStyles.itemByName(ts);
    tc = gres[i].cells;
    for (var j = 0; j < tc.length; j++){
        tc[j].clearCellStyleOverrides(true)
    };
};   


function grepFind(f){
    app.findGrepPreferences.findWhat=NothingEnum.NOTHING
    app.changeGrepPreferences.changeTo=NothingEnum.NOTHING
    app.findGrepPreferences.findWhat = f;
    return app.activeDocument.findGrep()
};

 

 

 

 

 

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 ,
Apr 09, 2022 Apr 09, 2022

Copy link to clipboard

Copied

LATEST

I pasted the wrong code for the selection version, just updated my first post

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