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
Ah, yes, ID's caption feature, which is incredibly useful to... some tiny minority of those who work in shops with fully managed assets. 😛
Do the captions use a defined style that could be used as a search target? ETA: Or has a specific object style been applied to the caption boxes?
Copy link to clipboard
Copied
Yes, they use a single defined style and corresponding substyles using delineated character styles based on the en dash embedded into the captions.
I'd love to just knock them all out and then page by page re-add them which would bring in all the changes driven inot the "Caption" field.
Copy link to clipboard
Copied
Hi @ht354, it sounds possible. Could you please post an example .indd which includes an image file that has been modified with a different caption?
- Mark
Copy link to clipboard
Copied
If the defined root style is a paragraph style and the captions aren't threaded in any way, this should work. Change "capt" to whatever the name of the pstyle is.
var doc = app.activeDocument;
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.appliedParagraphStyle = "capt";
var fs = doc.findText();
var i = fs.length;
while(i--) {
try {
fs[i].parentTextFrames[0].remove();
} catch(e) {
}
}
Copy link to clipboard
Copied
I can follow the logic in your code sample. I think it will do exactly what I need. I dropped it into a text file, saved it as ".jsx" and moved it into the Scripts Panel folder in the user library.
When I run the script I get the following error:
Could you direct me on what a Newbie has done wrong?
Thanks
Jeff
Copy link to clipboard
Copied
Hi Jeff, whatever text editor you used to save the code saved it as a Rich Text Format (rtf). Do you have a plain notepad editor? TextEdit for Mac saves stuff as RTF by default. I think you can change a setting somewhere to save it as plain text with the jsx extension.
Copy link to clipboard
Copied
Thanks for the direction, I did have RTF still enabled. However, I have run afoul with Style naming; I think. I get this error when I run the script
I did make sure to use straightened quotation marks around the Style name. It looks like it requires omething I'm not passing correctly.
Thanks
Jeff
Copy link to clipboard
Copied
Hi Jeff, Here’s a compiled version of @brian_p_dts ‘s script with your style name. Does the compiled version work from your ID Scripts panel?
https://shared-assets.adobe.com/link/cc9edd53-e98a-4b1a-6a0d-63f3be3e2afc
Copy link to clipboard
Copied
Hi Rob,
I downloaded your compiled script and tossed it into the "Scripts Panel Folder" and ran it. I received the following error;
I am breaking the caption naming rules? Does the style name
"PhotographCaptions" break any name conventions I am not aware of? I do have it in a Style Group. Does that figure into solving this problem? Does it need to be at the root level?
"
Copy link to clipboard
Copied
Sorry, I edited the style name but forgot to save before I posted. Try this one:
https://shared-assets.adobe.com/link/c1836f7d-b1fb-431e-7a0a-9223e4a07094
Copy link to clipboard
Copied
Had to move it into a different link folder for it to update:
https://shared-assets.adobe.com/link/c1836f7d-b1fb-431e-7a0a-9223e4a07094
Copy link to clipboard
Copied
Rob, I'm starting to feel like a real burden . . . I installed and ran your script and received the following error message.
Copy link to clipboard
Copied
Could you select the text in one of the captions and show a screen capture with your ParagraphStyles panel open?
Copy link to clipboard
Copied
I can't test right now, but I think I've seen this error before. I think it may occur when the style specified is in a style group (folder). For this reason I often use a little loop to get the style from document.allParagraphStyles.
- Mark
Copy link to clipboard
Copied
Here is a screenshot showing both the caption and the Paragraph style
Copy link to clipboard
Copied
Yes that is what I was wondering. Indesign doesn't match a style name string with a style when that style is contained in a style group, eg. "Caption Formatting" in your example. One way to fix is to specify the style fully. Replace line 3 of Brian's code with this:
app.findTextPreferences.appliedParagraphStyle = doc.paragraphStyleGroups.itemByName('Caption Formatting').paragraphStyles.itemByName('PhotographCaptions');
Copy link to clipboard
Copied
That did the trick! Thank you very much for the fix. Thanks also very much to @brianp311 who really got the solution cooking with his initial code.
The devil in me is thinking . . . (I fully admit I'm not programer) but is it simple to edit ;
fs[i].parentTextFrames[0].remove();
To re-add the captions in bulk?
Copy link to clipboard
Copied
The devil in me is thinking . . . (I fully admit I'm not programer) but is it simple to edit ;
fs[i].parentTextFrames[0].remove();
To re-add the captions in bulk?
Instead of removing the caption text frame, you can set the contents of that text frame to the caption you want. BUT this means you have to know what contents to put! ie. how do you know which graphic belongs to the caption you have targetted in Brian's script?
Copy link to clipboard
Copied
Theoretically, if the caption is touching the bottom of the img frame, you could try to capture it that way. But that's quite the undertaking. You could maybe write a separate code to execute Place Live Caption across all images in the document.
Copy link to clipboard
Copied
I guess I needed to include more details. The captions are embedded in the images using the "Caption" metadata field. So my thinking was, could the script then re-apply fresh captions by re-applying the "Generate Stais Caption" command? I wondered if the line parentTextFrames[0] had options to not only remove captions but also apply.
Copy link to clipboard
Copied
@ht354, I have written a script that applies a caption to a graphic that should help you here. First, can you post a photo with the caption metadata so I can test? - Mark
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Ah I see. That won't work with live captions (as far as I know) because that feature is limited to using set metadata fields, eg. description, credit, etc. Hmm. Do you need your custom "Caption" metadata field for anything else except here? If not, an easy solution would be to add multiple metadata fields to the text in whatever order you like. I can make that change easily. - Mark
Copy link to clipboard
Copied
Something might work since InDesign sees the Lightroom "Caption" metadata field as "Description." I currently add captions using the "Description" field.
I build the caption field by using Lightroom Find and Replace plugin and drive it all into the "Caption" field.
In this project I only use the "Caption" field exclusivley for image descriptions.