var myDoc = app.activeDocument; var myCaps= myDoc.textVariables.everyItem.getElements(); var myCap= myCaps.length; for (i=0; i<myCap; i--) myCaps[i].convertToText();
Thank you! I get an error message with that:
Error Number: 24
Error String: myDoc.textVariables.everyItem.getElements is not a function
maybe uniqued_tol wrote too fast?
Indeed, "everyItem.getElements" is not a function.
() is missing after everyItem.
To the effect uniqued_tol meant something like that:
But that would not work for text variables used in nested structures:
For example in grouped text frames or tables or footnotes and all other nested structures like pasted inside text frames, text frames in buttons, multistate objects (MSOs) etc.pp.
To catch all instances of your text variables—the variable used in the text—one has to convert every textVariableInstance.
If you want address simple Story objects—without catching the instances in tables and footnotes:
( Text frames in groups, buttons or MSOs will be addressed. )
To really catch all a bit more code is necessary.
Want to add something:
Did some tests with:
where I had one table t1 and another table t2 nested in a cell of t1.
Both tables had text var instances in their cells.
To my surprise, after executing the script all instances despite of their nested structure were converted to text.
Don't know why this did not happen in my first test where other, more complex nested structures were on the page:
Footnote, MSO, Group. Have to investigate this.
Also I found, that converting instances of text variables to text in text cells could lead to unnecssary cell overflow.
This could be a bug with InDesign tables.
After a bit testing I know where the problem is:
will only address the first instance of every text var used in the text.
Regardless of nested structures or not.
So that means:
You always have to work with textVariableInstances if you want to convert to text.
Hm. Me again on this confusing topic…
It's a bit more complex.
Currently I find no distinct rule what is converted when.
With converting textVariableInstances you are on the safer side.
Thank you very much, Laubender. I don't have any text in nestled structures, so this works perfectly for me. Much appreciated!
Hi again Laubender,
I've been working with this script over the past catalogue season, and it worked out beautifully. I just have one problem now: all my text variable footers get converted too, and since they live on master pages and read from paragraph styles on each page, they get converted as the variable name. Is there anyway to adjust the script so that it doesn't affect items in a locked layer?
if you want to leave out locked layers and master pages you have to:
1. Loop the layers of your document to see if there are locked ones. Store unlocked ones in an array.
2. Loop the result array to get all page items on the layer ( that would not include the items on the masters ).
3. Check the results for text frames and use convertToText() on all textVariableInstances of the found text frames.
Thanks, Uwe! I'm afraid I don't know how to translate that to code. I've only just started dipping me feet into scripting! Any tips you could offer would be super helpful.