Why does InDesign freeze when calling app.doScript() from a UXP plugin? Not always, but every other time. I can’t get a crash report because indesign doesn’t crash, it just freezes for a long time. InDesign v19.0.
const script_name = "Clear Overrides"
app.doScript(
clear_overrides,
ScriptLanguage.UXPSCRIPT,
[],
UndoModes.ENTIRE_SCRIPT,
script_name
)
function clear_overrides() {
console.log("Starting Clear Overrides")
try {
const stories = get_stories(doc)
for (let s of stories) {
if (s.textContainers[0].parentPage.parent != "[object MasterSpread]") {
s.clearOverrides()
s.footnotes.length &&
s.footnotes.everyItem().texts.item(0).clearOverrides()
s.tables.length &&
s.tables
.everyItem()
.cells.everyItem()
.texts.item(0)
.clearOverrides()
}
}
} catch (err) {
console.log(err)
}
}
function get_stories(range) {
try {
if (range.constructorName == "Document") {
let all_stories = range.stories.everyItem().getElements()
let stories = all_stories.filter(
(s) =>
s.textContainers[0].parentPage &&
s.textContainers[0].parentPage.parent != "[object MasterSpread]"
)
return stories
} else {
let story = range.parentStory
return story
}
} catch (err) {
console.log(err)
return []
}
}