Skip to main content
Inspiring
August 6, 2021
Answered

Script to find Variable Text and Convert to Text

  • August 6, 2021
  • 5 replies
  • 2108 views

Purpose:  Variable Text can be controlled with paragraph styles but will ignore the GREP styles.  Once converted to static text, the GREP styles kick in.

 

My sample code is here but I get errors at lines with colored text.  I'm hoping someone could look at this and if possible suggest something to make it work.   17 thank you's !

 

main();
function main() {

 

// Find variable text by Modificaton Date
app.findGrepPreferences.findWhat = ("~o");
app.selection[0].parentStory.findGrep();

 

// Convert variable to text
app.menuActions.item("$ID/Convert Variable to Text").invoke();

}

This topic has been closed for replies.
Correct answer jctremblay

Give this script a try for more flexibility... 

tomaxxiVARIprocessor by Marijan Tompa

5 replies

Braniac
August 6, 2021

Hi MadMac55,

also look into this post where I repaired the damaged code:

 

select every Variable Text Frame and turn it to static
Laubender, Feb 21, 2018

https://community.adobe.com/t5/indesign/select-every-variable-text-frame-and-turn-it-to-static/m-p/9657363#M86849

 

Regards,
Uwe Laubender

( ACP )

MadMac55Author
Inspiring
August 6, 2021

Oh nice, thank you for the follow-up on this.

jctremblayCorrect answer
Braniac
August 6, 2021

Give this script a try for more flexibility... 

tomaxxiVARIprocessor by Marijan Tompa
MadMac55Author
Inspiring
August 6, 2021

Jean-Claude, thank you!  This is incredibly useful.  You guys are amazing.   🙂

MadMac55Author
Inspiring
August 6, 2021

Fascinating approach, both of you.  So fast.  And flexible for other text variables as well.  Can't say thank you enough for sharing your expertise.   🙂

 

 

Braniac
August 6, 2021

Hi MadMac55,

if you try to use a menu action you have to select every of the found texts before you invoke it.

With your code you convert all text variable instances of all kind in your selection you started with.

 

Note: Texts have a collection of textVariableInstances you could loop. GREP is not necessary.

 

// Start with selected text:
var text = app.selection[0];

// Collect all text variable instances of all kind in this selected text:
var textVarInstances = text.textVariableInstances.everyItem().getElements();

// Loop the found text variable instances:
for( var n=0; n<textVarInstances.length; n++ )
{
	// Test if a particular one is of type Modification Date:
	if( textVarInstances[n].associatedTextVariable.variableType == VariableTypes.MODIFICATION_DATE_TYPE )
	{
		// Then convert that instance to text:
		textVarInstances[n].convertToText();
	};
};

 

Regards,
Uwe Laubender

( ACP )

Braniac
August 6, 2021

Try the following

main();
function main() {
// Find variable text by Modificaton Date
app.findGrepPreferences.findWhat = "~o";
var a = app.selection[0].parentStory.findGrep();
app.select(a)

// Convert variable to text
app.menuActions.item("$ID/Convert Variable to Text").invoke();

}

-Manan