7 Replies Latest reply on Sep 28, 2015 7:18 AM by Yohan828

    Unable to set kerning value

    Yohan828

      Hello Guys,

       

      I'm on an script which is setting the kerning value between characters in a textframe.

       

      The following is not working at all (it's giving me error - «the property is not applicable in the current state»)

       

           newTextFrame.words[0].insertionPoints[f].kerningValue = 10;

       

      However, i'm not getting error when using the kerningValue property of characters :-

           newTextFrame.characters[f].kerningValue = 10;

       

      On alert, it's even giving me '10' as set beforehand, but on my indesign document, all kerning values remains (0)

       

      Does anyone have an idea on how to solve this?

       

      Thanking you in advance

        • 1. Re: Unable to set kerning value
          G. Singelmann Level 3

          Does the first word actually have f insertion points?

           

          Or do you mean the f-nd insertion point of the frame, as you do with the character?

          • 2. Re: Unable to set kerning value
            pkahrel Adobe Community Professional & MVP

            How many insertion points does words[0] have? Fewer than f?

            • 3. Re: Unable to set kerning value
              Yohan828 Level 1

              The number of insertion points is 46 actually.  it's running inside a for loop:

               

              for (var f=0; f<newTextFrame.words[0].insertionPoints.length; f++)

              {

                    alert(newTextFrame.words[0].insertionPoints[f].kerningValue);

                    newTextFrame.words[0].insertionPoints[f].kerningValue = 10;

                   alert(newTextFrame.words[0].insertionPoints[f].kerningValue);

              }


              In fact, i'm getting the "property not applicable" error when alerting the kerning value.  When I remove the alerts,  there's no error, but still, no changes in the indesign document,  My final loop is as follows:


                  for (var e=0; e<newTextFrame.words.length; e++)

                     {

                          for (var f=0; f<newTextFrame.words[e].insertionPoints.length; f++)

                          {

                               newTextFrame.words[e].insertionPoints[f].kerningValue = 10;

                          }

                      }


              • 4. Re: Unable to set kerning value
                pkahrel Adobe Community Professional & MVP

                What happens if you do this:

                 

                newTextFrame.words.everyItem().insertionPoints.everyItem().kerningValue = 10;

                 

                Which InDesign version do you use?

                • 5. Re: Unable to set kerning value
                  G. Singelmann Level 3

                  When you start f with 0 you might as well use

                       newTextFrame.insertionPoints.everyItem().kerningValue = 10;

                  if I am not mistaken.

                  The first insertion point of a word is the one left of the first character.

                   

                  Otherwise your code works just fine.

                   

                  Try:

                       for (var e=0; e<newTextFrame.words.length; e++) {

                              for (var f=0; f<newTextFrame.words[e].insertionPoints.length; f++) {

                                  $.write( newTextFrame.words[e].characters[f].contents);               

                                   newTextFrame.words[e].insertionPoints[f].kerningValue = 10;

                              }

                          }

                   

                  to check if it is a specific character in your text that does not want to be kerned.

                  • 6. Re: Unable to set kerning value
                    Marc Autret Level 4

                    Hi all,

                     

                    Kerning regards insertion points between characters, so you'll usually get in trouble when targeting either the first or the last insertion points of a Story. When the kerningMethod is automated (as 'Optical' or 'Metrical') kerning values have a default amount which you can read using myInsertionPoint.kerningValue, but this command fails if the insertion point index is 0 (zero) or the last index in the Story. You then get the "property is not applicable in the current state" error.

                     

                    Anyway you can override kerning values. Peter has shown how to do this quickly:


                    myText.insertionPoints.everyItem().kerningValue = 50;

                     

                    or even


                    myText.kerningValue = 50; // all underlying insertion points are targeted as well

                     

                    Interestingly, such command allows to apply the overriding value to both the first and last insertion point (although this has no visual effect). And then myText.insertionPoints[0].kerningValue does not lead to a runtime error and actually returns the value (50).

                     

                    @+

                    Marc

                    • 7. Re: Unable to set kerning value
                      Yohan828 Level 1

                      Thnx Guys.  Its working fine now!