Skip to main content
Inspiring
March 30, 2020
Answered

Looking for a script to replace placeholder text in selected tablerows into numbering 1, 2, 3...

  • March 30, 2020
  • 1 reply
  • 586 views

I was working with this script to replace placeholder text "###" in a text-selection into numbering. However this obviously won't work with text in selected tablerows. Anyone any ideas?

#target indesign
var
    placeholder = "###",
    mFound, len, start = 1;
 
    if (app.selection[0] &&  (app.selection[0] instanceof "Text Frame" || app.selection[0].hasOwnProperty ("baseline") ) )
        var mStory = app.selection[0].parentStory;
    else { alert("Select target textFrame or some part of target text\rand try again!"); exit();}
 
app.findTextPreferences = null;
app.findTextPreferences.findWhat = placeholder;
mFound = mStory.findText();
len = mFound.length;
while (len-->0)
    mFound[len].contents = (len + start).toString();

 

This topic has been closed for replies.
Correct answer Manan Joshi

Try adding a new condition into your if else to accomodate selection of rows in table as well. Replace your if else with the following and then try

    if (app.selection[0] &&  (app.selection[0] instanceof "Text Frame" || app.selection[0].hasOwnProperty ("baseline") ) )
        var mStory = app.selection[0].parentStory;
	else if(app.selection[0] &&  app.selection[0].constructor.name == "Cell")
		mStory = app.selection[0]
    else { alert("Select target textFrame or some part of target text\rand try again!"); exit();}

 

-Manan

1 reply

Manan JoshiCorrect answer
Community Expert
March 30, 2020

Try adding a new condition into your if else to accomodate selection of rows in table as well. Replace your if else with the following and then try

    if (app.selection[0] &&  (app.selection[0] instanceof "Text Frame" || app.selection[0].hasOwnProperty ("baseline") ) )
        var mStory = app.selection[0].parentStory;
	else if(app.selection[0] &&  app.selection[0].constructor.name == "Cell")
		mStory = app.selection[0]
    else { alert("Select target textFrame or some part of target text\rand try again!"); exit();}

 

-Manan

cramikAuthor
Inspiring
March 31, 2020

Works like a charm! Thx!