问题
In my script, I am copying a table of cells that have a lot of text in them. This text has a bunch of custom hyphenation rules that are saved in the document dictionary, NOT in the user dictionary. This is accessed in the UI by opening User dictionary and selecting the document under Target.
When copying the table to another document, these rules are unfortunately not copied with it, and the text is changed.
How can I access this custom document dictionary so that my hyphenations are retained in the target document?
It is possible to access the user dictionary with UserDictionary
, but where is the document dictionary located?
回答1:
Answering this myself since I finally found the proper class to use:
The document dictionary can be accessed using HyphenationExceptions
. To get all custom hyphenations from my target document, I did the following:
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
}
}
For some reason, it seems that it is NOT possible to get a certain HyphenationException using its name.
In other words, the below code does not work (it actually gives me a Norwegian dictionary):
var mySourceDictionary = app.activeDocument.hyphenationExceptions.item("Danish");
For this reason, I had to loop the array until I found the one I needed: ("Danish").
来源:https://stackoverflow.com/questions/21972372/indesign-accessing-document-dictionary