6 Replies Latest reply on Mar 6, 2015 10:45 PM by selvam214

    Find without small caps italic and apply cstyle

    selvam214 Level 1

      Hi All,

      I have small caps (nested) line with italic text (see the screenshot), I have tried to apply the "small caps italic" character style successfully. After that I will apply the "small caps" cstyle to only small cap's text, but not working my script, can you please correct this.

       

       

       

      var itals = ["Italic", "Light Italic", "LightItalic", "Book Italic", "Cursive", "Light Condensed Italic", "Book Condensed Italic", "Ultra Condensed Italic", "Ultra Italic", "Condensed Italic", "ThinItalic", "BookItalic", "LightItalic", "BookItalic", "UltraItalic"]

      var smallCaps = ["Small Caps & Oldstyle Figures", "55Roman Small Caps & Oldstyle Figures", "smallCaps"];

      Fix_All_SmallCaps_Italic()

      function Fix_All_SmallCaps_Italic()

      {

          try

          {

              var myCStyle7 = app.activeDocument.characterStyles.item("15 Small Caps Italic").name;

              }

          catch(myError)

          {

              var myCStyle7 = app.activeDocument.characterStyles.add({name: "15 Small Caps Italic", capitalization: Capitalization.SMALL_CAPS, fontStyle: "Italic"})

              }

       

          for(i=0; i<itals.length; i++)

          {

              app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

              app.findTextPreferences.fontStyle = itals[i];

              app.findTextPreferences.capitalization = Capitalization.SMALL_CAPS;

       

              app.changeTextPreferences.appliedCharacterStyle = "15 Small Caps Italic";

              app.activeDocument.changeText();

              }

      }

       

      //~ exit(0);

      Fix_All_SmallCaps();

       

      function Fix_All_SmallCaps()

      {

       

      try

      {

          var myCStyle6 = app.activeDocument.characterStyles.item("15 Small Caps").name;

          }

      catch(myError)

      {

          var myCStyle6 = app.activeDocument.characterStyles.add({name: "15 Small Caps", capitalization: Capitalization.SMALL_CAPS})

          }

       

       

      for(sc=0; sc<smallCaps.length; sc++)

      {

          app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

          app.findTextPreferences.fontStyle = smallCaps[sc];

          app.changeTextPreferences.appliedCharacterStyle = "15 Small Caps";

          app.activeDocument.changeText();

          }

       

       

      //find attribute and apply character style

       

      var myDoc = app.activeDocument; 

      var mcstyle = app.activeDocument.characterStyles.item("15 Small Caps Italic").name;

       

      app.findTextPreferences = app.changeTextPreferences = null;

      app.findTextPreferences.capitalization = Capitalization.SMALL_CAPS;

      app.changeTextPreferences.appliedCharacterStyle = "15 Small Caps";

      var myFind = myDoc.findText(); 

       

      for(var j=0; j<myFind.length; j++){

      if(myFind[j].appliedCharacterStyle.name == mcstyle){

          alert(myFind[j].contents)

          continue;

          }

      else if (myFind[j].appliedCharacterStyle.name != mcstyle){

      app.activeDocument.changeText();}

      }

      }

       

       

       

      Screen shot 2015-03-05 at 5.34.11 PM.png

        • 1. Re: Find without small caps italic and apply cstyle
          selvam214 Level 1

          Hi All,

          Kindly let me if not clear this request.

           

           

           

          Actually the second selection need "That's" only, not a complete line.

          • 2. Re: Find without small caps italic and apply cstyle
            Jump_Over Level 5

            Hi,

             

            I would start with setting a goal you are going to reach.

            There is

            goodMixedCharStyle (fontStyle "Italic" and smallCaps)

              and

              goodCharStyle (just smallCaps)

            If my uderstanding is good, your code is doing following steps:

            1. find wrong italic font styles (but capitalized) and apply goodMixedCharStyle
            2. find wrong capitalisation font styles and apply goodCharStyle (however keep wrong fontStyle applied)
            3. find every capitalized text and if:
              •   goodMixedCharStyle is applied ==> alert it
              •   otherwise ==> apply goodCharStyle (keep format as it is, charStyle applied)

             

            Was it your goal?

             

            Jarek

            • 3. Re: Find without small caps italic and apply cstyle
              selvam214 Level 1

              Hi Jarek,

              Thanks for analyzing with different way. Yes, you're correct. I need to apply the Cstyle as per below:

               

              Step 1:

              I will find the goodMixedCharStyle (fontStyle "Italic" and smallCaps) and apply style name 1.

               

              Step 2:

              Then, I will find the goodCharStyle (just smallCaps) and apply style name 2.

               

              But,

              once applied the "style name1" (step 1), the "goodMixedCharStyle" having with small caps. So the "step2" script to find "style name1" also and apply to the "style name 2".

               

               

               

               

              I'll change my code as per your guidance and get back to you if any assistance.

               

              Thanks for the effort Jarek.

               

              Selva.

              • 4. Re: Find without small caps italic and apply cstyle
                selvam214 Level 1

                Hi Jarek,

                I can't get the output,

                 

                 

                itals = ["Italic", "Light Italic", "LightItalic", "Book Italic", "Cursive"]

                 

                 

                Fix_All_SmallCaps_Italic()

                function Fix_All_SmallCaps_Italic()

                {

                    try

                    {

                        var myCStyle7 = app.activeDocument.characterStyles.item("15 Small Caps Italic").name;

                        }

                    catch(myError)

                    {

                        var myCStyle7 = app.activeDocument.characterStyles.add({name: "15 Small Caps Italic"})

                        }

                   

                    try

                {

                    var myCStyle6 = app.activeDocument.characterStyles.item("15 Small Caps").name;

                    }

                catch(myError)

                {

                    var myCStyle6 = app.activeDocument.characterStyles.add({name: "15 Small Caps"})

                    }

                 

                 

                    for(i=0; i<itals.length; i++)

                    {

                        app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

                        app.findTextPreferences.capitalization = Capitalization.SMALL_CAPS;

                        app.findTextPreferences.fontStyle = itals[i]

                        var myFind = app.activeDocument.findText();

                        for (j=0; j<myFind.length; j++)

                        {

                        if (app.findTextPreferences.fontStyle == itals[i])

                        {

                            app.changeTextPreferences.appliedCharacterStyle = "15 Small Caps Italic";

                            app.activeDocument.changeText();

                            }

                        else if (app.findTextPreferences.fontStyle != itals[i])//I locked here

                        {

                            app.changeTextPreferences.appliedCharacterStyle = "15 Small Caps";

                            app.activeDocument.changeText();

                            }

                        }

                           

                        }

                }

                 

                 

                Can you please correct this.

                 

                 

                 

                 

                 

                selva

                • 5. Re: Find without small caps italic and apply cstyle
                  Jump_Over Level 5

                  Hi,

                   

                  1. so your charStyles has names only?

                  2. perhaps disable this line:

                      app.findTextPreferences.fontStyle = itals[i]

                   

                      so myFind array would match all smallCaps.

                  Now iterate through and use switch...case loop

                  I mean:

                  //...
                  switch (myFind[j].fontStyle) {
                      case "Italic":
                      case "Light Italic":
                      case "LightItalic":
                      case "Book Italic":
                      case "Coursive":
                            myFind[j].appliedCharacterStyle = myCStyle7;
                            break;
                      default: 
                            myFind[j].appliedCharacterStyle = myCStyle6;
                            break;
                      }
                  //...
                  
                  
                  


                  Jarek

                  (Modified; switch (myFind[j].fontStyle)

                  • 6. Re: Find without small caps italic and apply cstyle
                    selvam214 Level 1

                    Thanks for this Jarek.