0

I am having trouble deleting a document dictionary in InDesign CS 5.5.

InDesign Document Dictionary

I can clear the contents of a user dictionary using this script:

var myUserDictionaries = app.userDictionaries;
var myCountDict = myUserDictionaries.count();

for (var i = myCountDict-1; i >= 0; i-- ) {
    myUserDictionary = myUserDictionaries[i];
    var myAddedWords = myUserDictionary.addedWords;
    myUserDictionary.removeWord(myAddedWords);
}

But this leaves the document dictionary untouched. A few years ago, this was an unresolved problem as seen on the Adobe forums.

But I found this code (from here):

var myHyphenations = app.activeDocument.hyphenationExceptions;
for (var i = 0; i < myHyphenations.length; i++) {
    if (myHyphenations[i].name === "Danish") {
        var mySourceDictionary = myHyphenations[i];
        mySourceHyphenations = mySourceDictionary.addedExceptions;
        break
        }
    }

Which seems to be able to access the document dictionary. But my question is (since I'm not much of a programmer), how to modify this code to clear or delete the document dictionary (for English:USA)?

Community
  • 1
  • 1
Nathan
  • 1,483
  • 3
  • 18
  • 41

1 Answers1

0

Actually this turned out to be more simple than I anticipated.

Here's the script that will delete/clear a document dictionary:

var myHyphenations = app.activeDocument.hyphenationExceptions;
var myCountDict = myHyphenations.count();
for (var i = myCountDict-1; i >= 0; i-- ) {
    myHyphenation = myHyphenations[i];
    var myAddedWords = myHyphenation.addedExceptions;
    myHyphenation.removeException(myAddedWords);
    }
Nathan
  • 1,483
  • 3
  • 18
  • 41
  • Any idea how to clear words added to the “All languages” language? The code in the answer does not clear words added to the it, as "All languages" does not even seem to exist inside app.activeDocument.hyphenationExceptions. Adding, inside the loop, $.write(myHyphenation.name + ": " + myAddedWords.length + "\n") (which reports to the console each language inside the document’s dictionary along with the number of words added to it) before removeException does not list any item with the number of words added to “All languages“ (nor all other items get those words either). – elmimmo Jul 16 '23 at 06:51
  • @elmimmo Did you try the code in the question? It's been a while since I've used this, but the user dictionary clear code would probably work. – Nathan Jul 28 '23 at 17:25
  • it works for all languages except the “All languages” one. See https://community.adobe.com/t5/indesign-discussions/manage-hyphenation-exceptions-in-all-languages-language-via-scripting/m-p/13941128 – elmimmo Jul 30 '23 at 08:46