Copy link to clipboard
Copied
I have inherited a project where most of the captions embedded in the images have been heavily edited. They all reside in Lightroom and have been placed into the document using Bridge. I now need to re-link the images, which is no problem, but I can't see myself manually removing 450 individual caption text boxes.
Is there a script or a command I've somehow missed that allows the bulk removal of all the captions?
Copy link to clipboard
Copied
Okay, so when you set up the text variable to go with the script, just set it to use the description field. Will that work for you?
Copy link to clipboard
Copied
The problem I've run into is related to the live caption limitation where carriage returns are ignored so text won't flow. It runs back over itself.
Is there any way of enabling the static caption property after removing the old captions?
Copy link to clipboard
Copied
Oh yeah, I see what you mean. Unfortunately that is a shortcoming of live captions. The quickest workaround I can think of is to convert the live captions to normal text. I'll add a line to the script I posted shortly to show this. It means that if the XMP data in the graphic changes, the captions won't update, but you should be able to run the script again to update them all.
- Mark
Copy link to clipboard
Copied
Thanks, I look forward trying out your solution.
Copy link to clipboard
Copied
@ht354, I think I have something that might work in your situation. I have expanded @brianp311's code to replace the text with a live caption text variable. To use it you must (a) create a "Metadata Caption" text variable (Type menu > TextVariables > Define) and choose the metadata field (I chose "Credit", for example). Then make sure the name of this variable is the same as that specified in the settings of the script (captionVariableName).
- Mark
/**
* by @brianp311 and @m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/how-to-remove-all-static-captions-from-document/m-p/13328307
*/
var settings = {
// will search for text in this paragraph style
captionParagraphStyleName: 'PhotographCaptions',
// will replace with instance of this text variable
captionVariableName: 'Description',
// live captions don't allow for normal line breaks,
// so here is option to convert to normal text
convertLiveCaptionsToNormalText: true,
};
function main() {
var doc = app.activeDocument,
liveCaptionVariable = getByName(doc.textVariables, settings.captionVariableName),
captionParagraphStyle = getByName(doc.allParagraphStyles, settings.captionParagraphStyleName);;
// some error checking
if (
liveCaptionVariable == undefined
|| !liveCaptionVariable.isValid
) {
alert('Could not find Text Variable "' + settings.captionVariableName + '"');
return;
}
if (
captionParagraphStyle == undefined
|| !captionParagraphStyle.isValid
) {
alert('Could not find Paragraph Style "' + settings.captionParagraphStyleName + '"');
return;
}
// do the find
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.appliedParagraphStyle = captionParagraphStyle;
var found = doc.findText();
// set contents of each found text frame
// to the live captions text variable
for (var i = 0; i < found.length; i++) {
var text = found[i].parentStory;
// clear the current contents
text.contents = '';
// add the text variable instance
var tv = text.textVariableInstances.add();
// and link it to the live caption text variable
tv.associatedTextVariable = liveCaptionVariable;
if (settings.convertLiveCaptionsToNormalText == true)
// convert to normal text
tv.convertToText()
}
} // end main
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Script');
function getByName(things, name) {
for (var i = 0; i < things.length; i++)
if (things[i].name == name)
return things[i];
};
Edit: added option to convert to normal text because Live Captions kinda suck. 😞
Copy link to clipboard
Copied
I also get the error if I put the style in a group, @m1b ’s itemByName line should work.
Copy link to clipboard
Copied