Copy link to clipboard
Copied
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();
}
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
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
...
Give this script a try for more flexibility...
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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 )
Copy link to clipboard
Copied
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. 🙂
Copy link to clipboard
Copied
Give this script a try for more flexibility...
Copy link to clipboard
Copied
Jean-Claude, thank you! This is incredibly useful. You guys are amazing. 🙂
Copy link to clipboard
Copied
Jean-Claude thankyou for sharing this script, personally it's a game changer!!
Copy link to clipboard
Copied
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
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Oh nice, thank you for the follow-up on this.