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

Script to find Variable Text and Convert to Text

Contributor ,
Aug 06, 2021 Aug 06, 2021

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();

}

TOPICS
Scripting
2.2K
Translate
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

correct answers 3 Correct answers

Community Expert , Aug 06, 2021 Aug 06, 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

Translate
Community Expert , Aug 06, 2021 Aug 06, 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.every
...
Translate
Community Expert , Aug 06, 2021 Aug 06, 2021

Give this script a try for more flexibility... 

tomaxxiVARIprocessor by Marijan Tompa
Translate
Community Expert ,
Aug 06, 2021 Aug 06, 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

Translate
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 ,
Aug 06, 2021 Aug 06, 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 )

Translate
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
Contributor ,
Aug 06, 2021 Aug 06, 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.   🙂

 

 

Translate
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 ,
Aug 06, 2021 Aug 06, 2021

Give this script a try for more flexibility... 

tomaxxiVARIprocessor by Marijan Tompa
Translate
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
Contributor ,
Aug 06, 2021 Aug 06, 2021

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

Translate
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
New Here ,
Oct 25, 2024 Oct 25, 2024
LATEST

Jean-Claude thankyou for sharing this script, personally it's a game changer!! 

Translate
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 ,
Aug 06, 2021 Aug 06, 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/9...

 

Regards,
Uwe Laubender

( ACP )

Translate
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
Contributor ,
Aug 06, 2021 Aug 06, 2021

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

Translate
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