Hi @Liam1965, you can try this script I just wrote. It will remove form fields from all open documents, and save each document with a suffix (so that it won't save over the original). Let me know if it's useful.
- Mark
/**
* Remove all form fields from all open documents,
* and save each document with the suffix '_NO_FIELDS'
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/scripting-find-all-form-fields-and-remove/m-p/14000885
*/
function main() {
var fileSuffix = '_NO_FIELDS',
thingPlural = 'formFields',
docs = app.documents,
counter = 0;
for (var i = docs.length - 1; i >= 0; i--) {
var doc = docs[i],
path = doc.fullName.fsName.replace(/(\.[^\.]+)$/, fileSuffix + '$1'),
things = doc[thingPlural].everyItem().getElements();
if (doc.groups.length > 0)
// also collect things in groups
things = things.concat(doc.groups.everyItem()[thingPlural].everyItem().getElements());
if (doc.stories.length > 0) {
// also collect any anchored things
things = things.concat(doc.stories.everyItem()[thingPlural].everyItem().getElements());
if (doc.stories.everyItem().tables.length > 0)
// also collect any thing in tables
things = things.concat(doc.stories.everyItem().tables.everyItem().cells.everyItem()[thingPlural].everyItem().getElements());
}
// remove each thing
for (var j = things.length - 1; j >= 0; j--) {
if (things[j].isValid) {
things[j].remove();
counter++;
}
}
// save as new document and close
doc = doc.save(File(path));
doc.close(SaveOptions.NO);
}
alert('Removed ' + counter + ' form fields.');
} // end main
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Remove All Form Fields');
Edit 2023-08-11: as per @TᴀW and @Laubender's comments, I now guess that the OP wishes to remove all form fields, not just text fields, so I have updated. If you want just textBoxes, or radioButtons, etc, change the `thingPlural` string.
Edit 2023-08-11: as @Laubender suggested, I added an extra line to collect things from groups.
Edit 2024-01-11: added some checks to avoid errors in documents that don't have stories, groups, or tables! Thanks to @Joel Cherney for the testing.