Copy link to clipboard
Copied
I have a 260+ page catalogue that uses live captions for every product image. These need to get converted to static captions for a step of our process and I'd like to have a script that converts all my live captions at once rather than going through the documents page by page and selecting the text boxes. I found an old discussion here with a script that is supposed to do that, but it doesn't work for me. See here:
convert live captions to static on all pages?
I'd be thrilled to get some help with this!
Thanks,
Ã…sa
Hi Ã…sa,
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:
app.documents[0].textVariables.everyItem().convertToText();
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 instanc
...Copy link to clipboard
Copied
var myDoc = app.activeDocument; var myCaps= myDoc.textVariables.everyItem.getElements(); var myCap= myCaps.length; for (i=0; i<myCap; i--) myCaps.convertToText();
Copy link to clipboard
Copied
Thank you! I get an error message with that:
JavaScript Error!
Error Number: 24
Error String: myDoc.textVariables.everyItem.getElements is not a function
Any ideas?
Copy link to clipboard
Copied
Hi Ã…sa,
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:
app.documents[0].textVariables.everyItem().convertToText();
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. )
app.documents[0].stories.everyItem().textVariableInstances.everyItem().convertToText();
To really catch all a bit more code is necessary.
Regards,
Uwe
Copy link to clipboard
Copied
Want to add something:
Did some tests with:
app.documents[0].textVariables.everyItem().convertToText();
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.
Regards,
Uwe
Copy link to clipboard
Copied
After a bit testing I know where the problem is:
app.documents[0].textVariables.everyItem().convertToText();
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.
Regards,
Uwe
Copy link to clipboard
Copied
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.
Regards,
Uwe
Copy link to clipboard
Copied
Thank you very much, Laubender. I don't have any text in nestled structures, so this works perfectly for me. Much appreciated!
Copy link to clipboard
Copied
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?
Thanks!
Ã…sa
Copy link to clipboard
Copied
Hi Ã…sa,
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.
Regards,
Uwe
Copy link to clipboard
Copied
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.