Skip to main content
Phil 815
Inspiring
September 8, 2023
Answered

Find text in table by character style

  • September 8, 2023
  • 2 replies
  • 491 views

Hi all, I'm hoping someone could assist me with my script to find any text in a selected table that has a given character style. Below is my approach but findGrep() isn't returnng any matching results. This strategy seems to work when I search by paragraph style so I'm not sure why it doesn't translate to character style. Any help would be appreciated!

 

    app.findPreferences = null;
    app.changePreferences = null;
    app.findGrepPreferences.appliedCharacterStyle = characterStyle;
    const textFound = selection.findGrep();
    updateTracking(textFound, trackingToAdd);

 

 

This topic has been closed for replies.
Correct answer Phil 815

Solved it! I needed to clear out 

findGrepPreferences instead of findPreferences.  I think findPreferences might be a deprecated method at this point, not sure. This did the trick: 
  

 

app.findGrepPreferences = inDesign.NothingEnum.NOTHING;
app.findGrepPreferences.appliedCharacterStyle = characterStyle;
const textFound = selection.findGrep();
updateTracking(textFound, trackingToAdd);

 

2 replies

Peter Kahrel
Community Expert
Community Expert
September 8, 2023

Do you know for sure that the style is used in the table? (Sorry, had to ask)

Is the selection a table? Not an insertion point, or a cell, for instance?

Phil 815
Phil 815Author
Inspiring
September 8, 2023

Haha no worries it's worth asking since we sometimes overlook the small details. It is used in the table, the solution I found is in a reply to your original response. Thanks for taking a look at it with me!

Peter Kahrel
Community Expert
Community Expert
September 8, 2023

If 'characterStyle' is a string, try the object, i.e.

app.activeDocument.characterStyles.item(characterStyle);

 

Phil 815
Phil 815Author
Inspiring
September 8, 2023

Thanks Peter. Unfortunately that did not work. Using the string or the actual style (as you suggested) both seem to load a valid style to the findGrepPreferences, it's just not locating the characters with that style for some reason.