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

Struggling to script removal of addedWords from UserDictionary

Adobe Employee ,
Nov 17, 2010 Nov 17, 2010

Copy link to clipboard

Copied

First, I know, I work for Adobe, can I just ask some developer here? Yes, but I ask a lot from them already, and I try to give to the forum community, so I'm trying to get some in return 🙂

I'm trying to help a customer who has a lot of CS3 documents that have added words to dictionaries that have been embedded in the document (meaning, targeting the doc rather than the external file. These are proving problematic, and while I've got engineering looking into why that is, I'm hoping to create a script to remove the items as a workaround in the meantime. Here's the simple script I have:

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

for (var i = 1; i <= myCountDict; i++ ) {
    myUserDictionary = myUserDictionaries;
    var myAddedWords = myUserDictionary.addedWords;
    myUserDictionary.removeWord(myAddedWords);
}

The problem I get when I try to run this is "Object is invalid" for line 6: var myAddedWords = myUserDictionary.addedWords;

I know I've got a valid UserDictionary and the addedWords property is supposed to return an array of strings. What am I doing wrong? And, yes, I'm a noob.

Thanks for any help anyone can offer.

TOPICS
Scripting

Views

1.0K

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
LEGEND ,
Nov 17, 2010 Nov 17, 2010

Copy link to clipboard

Copied

Hi Matthew,

No need to apologize! Glad to help!

The problem is probably that you are looping forwards instead of backwards. When you remove all the words, the dictionary is probably removed, and the object reference becomes invalid.

Ah. I just noticed that you are starting with the length. Javascript is 0 based.

Change the loop to:

for (var i = myCountDict-1; i >= 0; i-- ) {

Harbs

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
LEGEND ,
Nov 17, 2010 Nov 17, 2010

Copy link to clipboard

Copied

Also:

I'm not sure the script will help the problem.

There's no scripting support for document user dictionaries. There's only support for the app ones. This is a glaring omision that I've already asked to be fixed. Maybe you can use some of your clout to get that done!

Harbs

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
Adobe Employee ,
Nov 17, 2010 Nov 17, 2010

Copy link to clipboard

Copied

Harbs,

Thanks. I always make that same error when i come to making a loop. Trouble is, I only take a stab at it every couple of years, so not much sticks.

And, sure enough, the app dictionary added words are deleted, but not the document ones. I'll take it up with engineering and see if there is a workaround or get it considered for addition in a future release.

Cheers!

Matthew

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 16, 2014 Nov 16, 2014

Copy link to clipboard

Copied

It's been a few years. But I am also looking to auto-remove the document dictionary words via script. Did you ever find a workaound? I'm using CS 5.5
I also posted here with some code that might open the door, but not sure how to implement it: javascript - InDesign: Delete Document Dictionary - Stack Overflow

Thanks,

Nathan

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 17, 2014 Nov 17, 2014

Copy link to clipboard

Copied

LATEST

Figured it out:

var myHyphenations = app.activeDocument.hyphenationExceptions;

var myCountDict = myHyphenations.count();

for (var i = myCountDict-1; i >= 0; i-- ) {

    myHyphenation = myHyphenations;

    var myAddedWords = myHyphenation.addedExceptions;

    myHyphenation.removeException(myAddedWords);

    }

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