Skip to main content
Participant
June 13, 2022
Question

hyphenationExceptions in Dictionary

  • June 13, 2022
  • 3 replies
  • 900 views

Indesign javascript object model returns incorrect name for the below line,

 

app.documents[0].hyphenationExceptions.itemByName("English: UK").name.

 

It returns,

English: USA.

 

How it is possible. 

 

Regards,

Dillibabu.

This topic has been closed for replies.

3 replies

Community Expert
June 13, 2022

This line will fail with an error:

try{
doc.hyphenationExceptions.itemByName( "Arabic" ).name;
}catch(e)
{
	$.writeln( "ERROR: " + e.number +", "+ e.message );
}

// RESULT: "ERROR: 1, name"

 

Because Arabic is listed as the last entry in the collection of hyphenation exceptions.

At least with my installed German InDesign 2022 version 17.3.0 on Windows 10.

 

The bug is very old. Can see it already with InDesign CS6 version 8.1.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

 

rob day
Community Expert
Community Expert
June 13, 2022

You might have to write your own function

 

 

var hbn = getHEByName("English: UK")
$.writeln(hbn.name)


/**
* Get Hyphenation Exception by Name 
* @ param name to get 
* @ return hyphenation exception 
* 
*/
function getHEByName(n){
    var h = app.documents[0].hyphenationExceptions;
    var he
    for (var i = 0; i < h.length; i++){
        if (h[i].name == n) {
            he = h[i]
        } 
    };   
    return he
}

 

Participant
June 13, 2022

Thank you. We can write a custom function to get by name. But what is the use of  the below,

hyphenationExceptions.itemByName()

 I want to mention the above line is working wrong.

rob day
Community Expert
Community Expert
June 13, 2022

But what is the use of the below

 

Looks like a bug

rob day
Community Expert
Community Expert
June 13, 2022

Hi @dillibabum29191024 , Looks like the entire collection is off by 1:

 

$.writeln("Looking for Bulgarian — " + app.documents[0].hyphenationExceptions.itemByName("Bulgarian").name + "\r\r")
var h = app.documents[0].hyphenationExceptions


for (var i = 0; i < h.length; i++){
    $.writeln(h[i].name)
};   


/* Return

Looking for Bulgarian — Catalan

bn_IN
gu_IN
hi_IN
kn_IN
ml_IN
mr_IN
or_IN
pa_IN
ta_IN
te_IN
Bulgarian
Catalan
Czech
Danish
German: Swiss
de_CH_2006
German: Reformed
de_DE_2006
Greek
English: Canadian
English: UK
English: USA
English: USA Medical
Spanish: Castilian
Estonian
Finnish
French: Canadian
French
Croatian
Hungarian
Italian
Lithuanian
Latvian
Norwegian: Bokmal
Dutch
nl_NL_2005
Norwegian: Nynorsk
Polish
Portuguese: Brazilian
Portuguese: Orthographic Agreement
Portuguese
Romanian
Russian
Slovak
Slovenian
Swedish
Turkish
Ukrainian */
Participating Frequently
July 20, 2023

As noted in this other thread about hyphenation exceptions added to the “All languages” language, I wonder if this bug is the reason why there seems to not exist scripting support to access only the hyphenation exceptions, even though there is for words added to all other languages. As if some parts of the code did account for the “All languages” language (which inside IDML files it is named “Neutral”) but not others and that's why “the entire collection is off by 1”.

Participating Frequently
July 20, 2023

I meant to write “…to access only those hyphenation exceptions…”.