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

How to remove all static captions from document?

Participant ,
Nov 03, 2022 Nov 03, 2022

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?

TOPICS
How to , Import and export , Performance , Publish online , Scripting

Views

958

Translate

Translate

Report

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 1 Correct answer

Community Expert , Nov 07, 2022 Nov 07, 2022

Yeah, I suspected it was in a group. Should have mentioned it up high. Glad you got it working. Thanks @m1b and @rob day for the additional support. 

Votes

Translate

Translate
Community Expert ,
Nov 08, 2022 Nov 08, 2022

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?

Votes

Translate

Translate

Report

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
Participant ,
Nov 08, 2022 Nov 08, 2022

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?

 

Votes

Translate

Translate

Report

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 ,
Nov 08, 2022 Nov 08, 2022

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

Votes

Translate

Translate

Report

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
Participant ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

LATEST

Thanks, I look forward trying out your solution.

Votes

Translate

Translate

Report

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 ,
Nov 07, 2022 Nov 07, 2022

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. 😞

Votes

Translate

Translate

Report

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 ,
Nov 07, 2022 Nov 07, 2022

Copy link to clipboard

Copied

 I also get the error if I put the style in a group, @m1b ’s itemByName line should work.

Votes

Translate

Translate

Report

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 ,
Nov 07, 2022 Nov 07, 2022

Copy link to clipboard

Copied

Yeah, I suspected it was in a group. Should have mentioned it up high. Glad you got it working. Thanks @m1b and @rob day for the additional support. 

Votes

Translate

Translate

Report

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