Skip to main content
Inspiring
December 10, 2024
Question

Adding Text variables (javascript)

  • December 10, 2024
  • 1 reply
  • 224 views

Is it possible to add a text variable and set all options via js?

var myV = app.activeDocument.textVariables.add({name: 'TCD', variableType: VariableTypes.MATCH_CHARACTER_STYLE_TYPE});
myV.preferences.searchStrategies = SearchStrategies.LAST_ON_PAGE;
myV.searchStrategies = SearchStrategies.LAST_ON_PAGE;

 

The second and the third line don't work. Is it possible to set the options like search strategies, characterStyle, text after & before etc. via script?

MatchCharacterStyleType is read only.

This topic has been closed for replies.

1 reply

m1b
Community Expert
Community Expert
December 10, 2024

Hi @mateuszp13156491, you need to set the variableOptions of the textVariable, which in this case will be a MatchCharacterStylePreference object. So use this in your code:

myV.variableOptions.searchStrategy = SearchStrategies.LAST_ON_PAGE;

- Mark