4 Replies Latest reply on Oct 31, 2009 8:27 AM by Peter Kahrel

    How to call "Hyphenate" option and its result?

    தமிழரசன் ( Thamilarasan)

      Hi all

       

      In indesign we can check a word's correct hyphenation using edit->spelling->dictionary=>hyphenate. Through scripting how can we call that and get the result?

       

      thanks

      Thamil

        • 1. Re: How to call "Hyphenate" option and its result?
          AdobeScripts Level 3

          you can't - if something is in UI - it doesn't mean that it is available in scripting

           

          you can try and simulate this - by creating TextFrame and inserting your word and playing with width of this TextFrame ...

           

          robin

           

          www.adobescripts.co.uk

          • 2. Re: How to call "Hyphenate" option and its result?
            தமிழரசன் ( Thamilarasan) Level 1

            thanks robin

             

            Yes I tried that already. But it takes too much time.

            • 3. Re: How to call "Hyphenate" option and its result?
              [Jongware] Most Valuable Participant

              Is it logical to have InDesign hyphenate a word and then using a script to have InDesign check if it has been correctly hyphenated? Wouldn't it return the same result?

               

              "Hyphenate" is not available as an option in Javascript. The Help lists hyphenateAcrossColumns, hyphenateAfterFirst, hyphenateBeforeLast, hyphenateCapitalizedWords, hyphenateLadderLimit, hyphenateLastWord, hyphenateWordsLongerThan, hyphenation -- a boolean value, true or false --, HyphenationException, HyphenationExceptions, hyphenationExceptions, hyphenationVendor, hyphenationVendorList, hyphenationZone, and hyphenWeight -- almost all of them are the properties you change in the Hyphenation dialog.

               

              To check hyphenation independent from ID itself, you could take a look at this thread: http://forums.adobe.com/thread/502975 that seems to deal with the same "problem".

              An alternative is to locate a pre-hyphenated list of words and look up your suspicious words in that -- that's how I got the "80%" confidence rate I mentioned in that thread.

              • 4. Re: How to call "Hyphenate" option and its result?
                Peter Kahrel Adobe Community Professional & MVP

                > Is it logical to have InDesign hyphenate a word and then using a script

                > to have InDesign check if it has been correctly hyphenated? Wouldn't it return the same result?

                 

                Well, it would be useful if you could see how Indesign hyphenates. You could stare at some stories, but taking a list of words and displaying all possible hyphenation points is easier on the eyes. The script below does that: it shows where InDesign breaks words. Select some story and run the script. Or create a text frame, enter a word and run the script. It gets slower when there are many words to process.

                 

                The script uses the workaround that Robin mentioned, as have others before him: create a narrow (10 points wide) text frame, forcing overset, then widen the frame until it's no longer overset. That's when you have all breakpoints (almost all, anyway).

                 

                 

                Peter

                 

                if (app.selection.length > 0 && app.selection[0].parentStory.constructor.name == "Story")
                    hyphenate_wordlist (app.selection[0].parentStory);
                else
                    {alert ("Select a text frame."); exit ()}
                
                
                function hyphenate_wordlist (story)
                    {
                    app.scriptPreferences.enableRedraw = false;
                    var temp_frame = add_frame ();
                    var words = story.words.everyItem().getElements();
                    for (var i = words.length-1; i > -1; i--)
                        words[i].contents = hyphenate (temp_frame, words[i].contents);
                    temp_frame.remove ();
                    }
                
                
                function hyphenate (frame, word)
                    {
                    frame.contents = word;
                    var gb = [50, 50, 200, 60];
                    frame.geometricBounds = gb;
                    while (frame.overflows)
                        {
                        gb[3]++;
                        frame.geometricBounds = gb
                        }
                    return frame.lines.everyItem().contents.join ("~")
                    }
                
                
                function add_frame (w)
                    {
                    var doc = app.documents[0];
                    doc.viewPreferences.horizontalMeasurementUnits = doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
                    var tf = doc.textFrames.add ();
                    tf.texts[0].hyphenation = true;
                    var gb = [50, 50, 200, 60];
                    tf.geometricBounds = gb;
                    return tf
                    }