4 Replies Latest reply on Mar 16, 2009 9:04 PM by dhishok

    Finding fontStyle error....

      Hi everyone,

      I am just finding the font style "Italic" which is applied in the document. And replace it with newly created character style named "myCstyle". While running the script the character style is created but it shows some errors in finding. Find my CS3 MAC script below,

      //Creating character style for applied font styles...

      var myDoc = app.activeDocument;
      var myCstyle = myDoc.characterStyles.add({name: Itl, fontStyle: "Italic"})

      app.findTextPreferences.findWhat = app.appliedFontStyle("Italic");
      app.changeTextPreferences.changeTo = myCstyle;


      Please look into and help me for this. Thanks in advance

        • 1. Re: Finding fontStyle error....
          Level 1
          From VB ObjectBrowser:

          Property FindWhat As Variant
          Member of InDesign.FindTextPreference
          The FindTextPreference to find. as String or idNothingEnum enumerator

          Property ChangeTo As Variant
          Member of InDesign.ChangeTextPreference
          The replacement ChangeTextPreference. as String or idNothingEnum enumerator

          so you can't apply FontStyle and CharStyle to Properties awaiting for String type

          You need to set formatting you looking for to fontStyle and appliedCharacterStyle

          Property FontStyle As Variant
          Member of InDesign.FindTextPreference
          The name of the font style. as String or idNothingEnum enumerator

          Property AppliedCharacterStyle As Variant
          Member of InDesign.ChangeTextPreference
          The character style to search for or change to. as String, CharacterStyle or idNothingEnum enumerator

          There is no "appliedFontStyle" in VB so I'm not sure if it will be in JS ...

          here is example in VB:

          myInDi.FindTextFreferences.FontStyle = "Italic"
          myInDi.ChangeTextPreferences.AppliedCharacterStyle = myDoc.CharacterStyles.Item("Italic")


          • 2. Re: Finding fontStyle error....
            dhishok Level 1
            Hi robin,

            Thanks for your kind support. Now the script works fine. I have one more concern in this script, i have find the superscript and subscript texts and replace it with created 'sup' & 'sub' character styles. But my script doesn't find the text of superscript & subscript. Find my full script here. Please check it and help me for this.

            //To find Font style and replacing it with corresponding character styles
            //Script for CS3

            #target InDesign
            var myDoc = app.activeDocument;
            var Itl = myDoc.characterStyles.add({name: "Itl", fontStyle: "Italic"});
            var sup = myDoc.characterStyles.add({name: "sup", position: Position.superscript});
            var sub = myDoc.characterStyles.add({name: "sub", position: Position.subscript});

            app.findTextPreferences.fontStyle = "Italic";
            app.changeTextPreferences.appliedCharacterStyle = Itl;

            app.findTextPreferences.findTextPosition = Position.superscript;
            app.changeTextPreferences.appliedCharacterStyle = sup;

            app.findTextPreferences.findTextPosition = Position.subscript;
            app.changeTextPreferences.appliedCharacterStyle = sub;

            function setupFindText(find, change, foots, hidLayers, lockedLayers, lockedStories, masters) {
            app.findTextPreferences = null;
            app.changeTextPreferences = null;
            try { app.findTextPreferences.findWhat = find } catch(e) {};
            try {app.changeTextPreferences.changeTo = change } catch(e) {};
            app.findChangeTextOptions.properties = {
            includeFootnotes:(foots == null ? false : foots),
            includeHiddenLayers:(hidLayers == null ? false : hidLayers),
            includeLockedLayersForFind:(lockedLayers == null ? false : lockedLayers),
            includeLockedStoriesForFind:(lockedStories == null ? false : lockedStories),
            includeMasterPages:(masters == null ? false : masters),
            includeCaseSensitive:(caseSensitive == null ? false : caseSensitive)

            • 3. Re: Finding fontStyle error....
              [Jongware] Most Valuable Participant
              The fontStyle is still set to 'italic'.

              You might want to start by setting all findTextPreferences to nothing, because it will
              i continue
              with what was set the last time you searched.
              • 4. Re: Finding fontStyle error....
                dhishok Level 1
                Hi jongware,

                Wow! its working fine. What you said is exactly right. Thanks for your kind help. Have a nice day.