10 Replies Latest reply on Jul 21, 2009 6:08 AM by dhishok

    character formts preserving...

    dhishok Level 1

      Hi everyone,

       

      I am creating such character styles to control many character formats. Its working fine but when i find fontStyle "Bold" or then apply character style "Bold" to it. I want to skip this while the paragraph style's fontSyle itself "Bold" (or) paragraph style's fontSyle itself "Italic". So i have to find the paragraphs which fontStyle "Bold " applied and characterStyle "Bold" applied, if it is ture then the character style "None" is applied to it.

      If anyone help me out and it would be appreciated.

       

      Thanks in advace

      Thiyagu

        • 1. Re: character formts preserving...
          dhishok Level 1

          Please ignore my previous post...

           

           

          Hi everyone,

           

          I have developed the script for creating such character styles and applying it to control many character formats like Italic, Bold, Bold Italic, Superscript, subscript etc.... And its working fine. Mostly the heading levels fontStyles are "Bold" or "Bold Italic". And it is fixed in the paragraph style itself. So I don't want to apply character styles if the font styles are defaulted in the paragraph styles.

           

          To overcome this problem now i am trying to find the paragraphs with applied font Style "Bold" and also applied character Style "Bold", if the case is true then the character style "None" is applied to those paragraphs.

           

          Can anyone help me out and it would be appreciated. Also suggest me if there is any better way to do this.

           


          Thanks in advace

          Thiyagu

          • 2. Re: character formts preserving...
            [Jongware] Most Valuable Participant

            Can you post the part of the script that searches for the attributes and apply the right character style?

            It could be as easy as

             

            if (myFoundItems[x].appliedParagraphStyle.fontStyle == "Bold")

              .. apply "[None]";

            else

              .. apply "Bold";

             

            -- although you do not actually have to apply [None]; depending on circumstances, it might even backfire at you. In a bold paragraph style with a superscript text -- applied through a character style -- it would remove the superscript style.

            • 3. Re: character formats preserving...
              dhishok Level 1

              Dear Jongware,

               

              Thanks for your kind support. Now the script is working fine. Find the part of the script below.

               

              //=================

              myDoc = app.activeDocument;
              //Creates CStyles
              if (myDoc.characterStyles.item("cs_Itl") == null){
                  myDoc.characterStyles.add({name: "cs_Itl", fontStyle: "Italic"});}
              if (myDoc.characterStyles.item("cs_bl") == null){
                  myDoc.characterStyles.add({name: "cs_bl", fontStyle: "Bold"});}

              if (myDoc.characterStyles.item("cs_sup") == null){
                  myDoc.characterStyles.add({name: "cs_sup", position: Position.superscript});}

               

              //Apply CStyles
              app.findTextPreferences = app.changeTextPreferences = null;
              app.findTextPreferences.fontStyle = "Italic";
              app.changeTextPreferences.appliedCharacterStyle = "cs_Itl";
              app.documents.item(0).changeText();
              app.findTextPreferences.fontStyle = "Bold";
              app.changeTextPreferences.appliedCharacterStyle = "cs_bl";
              app.documents.item(0).changeText();

              setNull();
              app.findTextPreferences.position = Position.superscript;
              app.changeTextPreferences.appliedCharacterStyle = "cs_sup";
              app.documents.item(0).changeText();

               

              function setNull(){
                  app.findTextPreferences = NothingEnum.nothing;
                  app.changeTextPreferences = NothingEnum.nothing;
              }

               

              alert("OK");

              //=================

               

              But i am unable give "None" style for the items. Can you please suggest me for this.

               

               

              Thanks & Regards

              Thiyagu

              • 4. Re: character formats preserving...
                [Jongware] Most Valuable Participant

                I'm missing something here.

                 

                Now the script is working fine.

                 

                It is? These are all "change all" commands, so there is no differentation on what the actual paragraph contained. This snip will not do what you originally asked.

                 

                .. But i am unable give "None" style for the items.

                 

                Use "app.activeDocument.allCharacterStyles[0]" instead.

                1 person found this helpful
                • 5. Re: character formats preserving...
                  dhishok Level 1

                  Dear Jongware,

                   

                  Thanks for your kind and extended support. Now the [None] style is working fine.

                  These are all "change all" commands, so there is no differentation on what the actual paragraph contained.

                  Ya what you said is exactly right. So i have decided to do this action finally.

                   

                  //=============

                  app.findTextPreferences.appliedCharacterStyle="cs_bl"; //Bold Character Style

                  myText=app.findText(true);

                  for(i=myText.length; i>=0; i--)

                  {

                       if (myText[i].appliedParagraphStyle.fontStyle=="Bold")

                       {

                            myText[i].appliedCharacterStyle=app.activeDocument.allCharacterStyles[0];

                        }

                  }

                  //==============

                   

                  Same for Italic and Bold Italic font styles. Suggest me if it is ok.

                   

                  Thanks & regards

                  Thiyagu

                  • 6. Re: character formats preserving...
                    [Jongware] Most Valuable Participant

                    Yes, that's correct.

                     

                    You can even change it to

                     

                    myText=app.findText();

                    for(i=myText.length; i>=0; i--)

                    {

                        if (myText[i].appliedParagraphStyle.fontStyle=="Bold")

                        {

                              myText[i].appliedCharacterStyle=app.activeDocument.allCharacterStyles[0];

                    ||      } else

                    ||    {

                    ||          myText[i].appliedCharacterStyle=app.activeDocument.allCharacterStyles.item("cs_bl");

                    ||    }

                    }

                     

                    and run it without the changeText() command.

                     

                    A side note is that findText(true) reverses the found array for you. In this case, it's not important -- applying a new style does not cause the found text array to be invalidated --, but if you do change the text contents (using myText[i].contents = "Something"), you have to use either one of

                    1. findText (false) (the default) and for(i=myText.length; i>=0; i--) (manually going in reverse through the array)
                    2. or findText (true) and for(i=0; i<myText.length; i++) (manually going forward in the reversed array)
                    1 person found this helpful
                    • 7. Re: character formats preserving...
                      dhishok Level 1

                      Dear jongware,

                       

                      Thanks for your valuable suggestions.

                       

                      ||      } else

                      ||    {

                      ||          myText[i].appliedCharacterStyle=app.activeDocument.allCharacterStyles.item("cs_ bl");

                      ||    }

                       

                      While running the script it shows some error in this lines. So i have changed this to

                       

                      myText[i]=app.activeDocument.characterStyles.item("cs_ bl");

                       

                      otherwise everything is fine.

                       

                      Apart from this i need one help, how to find the contents or styled paragraphs within the page range? That is i have to do changes like change color to the find contents in the particular pages. Suggest me how do this?

                       

                       

                      Thanks

                      Thiyagu

                      • 8. Re: character formats preserving...
                        [Jongware] Most Valuable Participant

                        That's a new one for me.

                        Perhaps you can search for all items, and in the loop check which are inside your page range?

                        A recent post by Dave Saunders showed how to get the page of a random object, it might work on the array of found texts.

                         

                        (An alternative solution would be to select the text on these pages and do the find/change on the selection. It might be faster if the number of selected pages is small and the entire document is large.)

                         

                        ((And yet *another* possibility is make use of the observation that "TextFrame" also has findText/changeText methods. Perhaps you could loop over your pages, and inside that loop over all text frames, doing the replace.))

                        • 9. Re: character formats preserving...
                          dhishok Level 1

                          Thanks for your helpful tips.

                           

                          As you suggested if the fontstyle is defaulted with the paragraph style then we can able to put condition to set character style as [None]. Is there any way to set [None] style, if the contents have the nested style. Please suggest for this.

                          ((And yet *another* possibility is make use of the observation that
                          "TextFrame" also has findText/changeText methods. Perhaps you could
                          loop over your pages, and inside that loop over all text frames, doing
                          the replace.))

                          My exact requirement is to change "ANNO" swatch applied elements(Table - cell fill, cell stroke, rules, tint boxes etc...) into "Balck" in particular range of pages. How can i loop these page elements in a particular page range? Please suggest and help me to do this.

                           

                          Thanks in advance

                          Thiyagu

                          • 10. Re: character formats preserving...
                            dhishok Level 1

                            Dear Jongware,

                             

                            I have developed the script for creating such character styles and applying it to control many character formats like Italic, Bold, Bold Italic, Superscript, subscript etc.... And its working fine. In some of paragraphs the texts having nested styles. And it is fixed in the paragraph style. So I don't want to apply character styles if the texts are having nested styles.

                             

                            To overcome this problem now i am trying to find the nested styled contents, if the case is true then the character style "None" is applied to those paragraph contents. Find the part of script below.

                             

                            //=======================

                             

                            myDoc = app.activeDocument;

                             

                            try{
                            app.findTextPreferences = app.changeTextPreferences = null;
                            app.findTextPreferences.fontStyle = "Italic";
                            app.findTextPreferences.position = Position.normal;

                             

                            myFind=myDoc.findText(false);

                             

                            for(i=myFind.length-1;i>=0;i--)
                            {
                                if(myFind[i].contents.nestedStyles==null)
                                {
                                    myFind[i].appliedCharacterStyle="cs_Itl";
                                    }
                                else{
                                    myFind[i].appliedCharacterStyle=myDoc.allCharacterStyles[0];
                                    }
                                }
                            }
                            catch(r){alert(r);}

                             

                            alert ("Done");

                            //======================

                             

                             

                            Can anyone look into this and help me out. Also suggest me if there is any better way to do this.

                             


                            Thanks in advace

                            Thiyagu