4 Replies Latest reply on Apr 19, 2010 3:31 AM by Shonkyin

    error: applying font on paragraph style

    Shonkyin Level 3

      Hi All,

       

      I am facing a problem while applying font on paragraph style. Here below is my code.

       

       

      if (myDoc.paragraphStyles[a].appliedFont.name == "Helvetica Neue Light")

      {

      myDoc.paragraphStyles[a].appliedFont = 'Helvetica Neue LT Std';

      myDoc.paragraphStyles[a].fontStyle = '45 Light';

      }

      The error is "The requested font family is not available." but fonts installed properly and working fine while i am applying manually.
      If i have apply "Helvetica Neue Std 45 Light" font anywhere in my document (manual) only one time and run the script then its working fine.
      Where is problem??
      Any suggestion.
      Thanks,
      Shonky

        • 1. Re: error: applying font on paragraph style
          [Jongware] Most Valuable Participant

          The problem is, you cannot apply "'Helvetica Neue LT Std' because you don't have a style "Light" in that font; and you cannot apply the style

          "45 Light" first because you don't have a "Helvetica Neue 45 Light"!

           

          This is what they refer to as a classic "Catch-22" situation. Fortunately, there is another way: you can apply both font and style in one command:

           

          app.activeDocument.paragraphStyles[2].appliedFont = 'Univers LT\t45 Light';

           

          (Note the tab character inbetween font family and style.)

           

          Quite irritating is that your way does work when applied to text, instead of a paragraph style; for a moment, you'll get a pink text in the "font" [Helvetica Neue 45 Light] and when you apply just the style, all is well again.

          • 2. Re: error: applying font on paragraph style
            Shonkyin Level 3

            Thanks Jongware

             

            Its working fine.

             

            Can you please tell me why paragraph and character appliedFont giving different result.

             

             

            var myDoc = app.activeDocument;
            var myparastyle = myDoc.paragraphStyles.length;
            for(a=1; a<myparastyle; a++)
            {
            alert (myDoc.paragraphStyles[a].appliedFont.name)
            }
            
            var mycharstyle = myDoc.characterStyles.length;
            for(a=1; a<mycharstyle; a++)
            {
            
            alert (myDoc.characterStyles[a].appliedFont.name)
            }
            
             
            

             

             

            In paragraph styles its giving font name and font style but in character styles it giving "undefined", Why?

             

            I think result should be same in both cases but its not.

             

            Shonky

            • 3. Re: error: applying font on paragraph style
              [Jongware] Most Valuable Participant

              "Why", well, no idea really.

               

              If you import text, Indesign is happy to add [Unknown Fonts Like This] to paragraph styles, character styles, and to plain text as well. On the other hand, you can't do this in the interface -- if you have a font "Univers LT", you cannot select "Bold" to make it [Univers LT Bold]. Then again, you can using Search and Replace: if your font is Times, you can first replace all "Bold" to "55 Bold", then replace all "Times" to "Univers LT".

               

              It must be something inside the scripting engine. It may well be a too smart programmer, trying to "protect" you from doing this by accident ...

              1 person found this helpful
              • 4. Re: error: applying font on paragraph style
                Shonkyin Level 3

                Thank you very much.

                 

                Shonky