21 Replies Latest reply: Apr 25, 2012 5:21 AM by designmon79 RSS

    Tagging for Character Style

    designmon79 Community Member

      Hi All,

       

      Need to insert tagging (character style name) surrounding the text which has character styles applied in InDesign document.

       

      Example: This is <italic>an</italic> example of <bold>character style</bold> tagging text.

       

      Please provide JS code for this.

       

      Thanks in advance,

      Mon

        • 1. Re: Tagging for Character Style
          designmon79 Community Member

          Please help me on this.

           

          Need to insert applied character styles name as a coding surrounding text (character style) in my document.

           

          Example:

                               Vidit, <italic>omnissi</italic> te el molorunto <bold>berrunt</bold> et quas ulles et volorep elique pernatet aut ac.

           

           

          Thanks,

          Mon

          • 2. Re: Tagging for Character Style
            designmon79 Community Member

            Please help.

             

            Hi All,

             

            Can anybody help me on this. This is not an XML element. This is simple bold, italic etc. typestyle applied in the text and I need to apply characterstyle used as a tag before and after styled text.

             

             

            Its urgent. Please provide JS code.

             

            Thanks in advance,

            Mon

            • 3. Re: Tagging for Character Style
              designmon79 Community Member

              Please help.

              • 4. Re: Tagging for Character Style
                jonht Community Member

                I think a simple grep find/change will work, look at the image below.

                The .+ finds any character, one or more times,

                In the Change To field type the code you want to use eg <bold>$0</bold>, the $0 puts back what is found.

                Finally, in the Find Format area, select the formating that you are looking for.

                 

                findChange.jpg

                • 5. Re: Tagging for Character Style
                  designmon79 Community Member

                  Thanks for your time. I appreciate it.

                   

                  But I need Javascript code for this so that we can replace all the characterstyle with required code.

                   

                  Please help.

                   

                  Thanks!

                  Mon

                  • 6. Re: Tagging for Character Style
                    pkahrel Community Member

                    > But I need Javascript code for this

                     

                    Virtually demanding a script rarely helps. Maybe you should ask someone if they were willing to write the code for you. And if you offer to pay something for it I'm sure someone will sort you out.

                     

                    Peter

                    • 7. Re: Tagging for Character Style
                      designmon79 Community Member

                      Thanks, Peter for your advice.

                       

                      As I am a beginner in scripting that is why I ask for help. There are lots of free  js code provided by scripter in this forum.

                       

                      I need this for my personal interest not professionaly. My be there someone who help me to write this script (free).

                      • 9. Re: Tagging for Character Style
                        designmon79 Community Member

                        Thanks Larry for your support.

                         

                        Actully I need only simple coding to insert around character style. Provided link is for xmltags.

                         

                        Anyway thanks for your support.

                         

                         

                        Regards,

                        Mon

                        • 10. Re: Tagging for Character Style
                          designmon79 Community Member

                          Dear All,

                           

                           

                          I have tried myself. But there is a problem with my code. It selects characterStyle [NONE]. And add <> symbol before and after of every paragraph style. Actually, I need to insert <> symbol before and after character style applied text (see my First Query).

                           

                          How can we avoid NONE characterstyle in my below code. Please help.

                           

                           

                           

                          var myAppliedCStyle = [app.findGrepPreferences.appliedCharacterStyle]

                          app.findGrepPreferences = null;

                          app.changeGrepPreferences = null;

                           

                          app.changeGrepPreferences.changeTo = "<$0>";

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

                          {

                            app.findGrepPreferences.findWhat = ".+";

                          app.changeGrepPreferences.appliedCharacterStyle = myAppliedCStyle[i];

                          app.activeDocument.changeGrep();

                          }

                           

                          Thanks,

                          Mon

                          • 11. Re: Tagging for Character Style
                            Velprakash Community Member

                            Hi,

                                Try this. I'm also fresher...

                            First u have to create tags manually with names b, bi,i, sc (bold,bolditalic,italic, small caps)...

                            then execute this js...

                             

                            docObj=app.activeDocument;

                            xmlObj = docObj.xmlTags;

                            pageObj=docObj.pages.item(0);

                            myTextFrame=pageObj.textFrames.item(0);

                            myText=myTextFrame.parentStory.paragraphs.item(0);

                             

                             

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

                            app.findTextPreferences.fontStyle = "Bold";

                            app.changeTextPreferences.markupTag=xmlObj[0].name;

                            alert(app.changeTextPreferences.markupTag);

                            app.activeDocument.changeText();

                             

                             

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

                            app.findTextPreferences.fontStyle = "Bold Italic";

                            app.changeTextPreferences.markupTag=xmlObj[1].name;

                            alert(app.changeTextPreferences.markupTag);

                            app.activeDocument.changeText();

                             

                             

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

                            app.findTextPreferences.fontStyle = "Italic";

                            app.changeTextPreferences.markupTag=xmlObj[2].name;

                            alert(app.changeTextPreferences.markupTag);

                            app.activeDocument.changeText();

                             

                             

                            app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

                            app.findGrepPreferences.capitalization = Capitalization.SMALL_CAPS;

                            app.changeGrepPreferences.markupTag=xmlObj[4].name;

                            alert(app.changeGrepPreferences.markupTag);

                            app.activeDocument.changeGrep();

                            • 12. Re: Tagging for Character Style
                              designmon79 Community Member

                              I have already seen this code that link is provided by Larry. This code is for XML tags whereas there is no XML tag in my document.

                               

                              I just want to replace text using character style with character style name code i.e., <bold>, <italic> etc.

                               

                              I write below code, its working but adds code (< and >) before and after every paragraph. How to avoid NONE character style sheet in my code?

                               

                               

                              var myAppliedCStyle = [app.findGrepPreferences.appliedCharacterStyle]

                              app.findGrepPreferences = null;

                              app.changeGrepPreferences = null;

                               

                              app.changeGrepPreferences.changeTo = "<$0>";

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

                              {

                                app.findGrepPreferences.findWhat = ".+";

                              app.changeGrepPreferences.appliedCharacterStyle = myAppliedCStyle[i];

                              app.activeDocument.changeGrep();

                              }

                               

                              Thanks in advance,

                              Mon

                              • 13. Re: Tagging for Character Style
                                Velprakash Community Member

                                Hi mon,

                                I can't get ur question clearly. Please tell me with an simple example.

                                 

                                Thanks & Regards,

                                Vel.

                                • 14. Re: Tagging for Character Style
                                  designmon79 Community Member

                                  Hi Velprakash,

                                   

                                  In my document there are some character styles applied in text i.e., bold, italic, boldItalic, and superscript etc.,

                                   

                                  I want to use this character styles name as a code surrounding character style applied text, so that I can use this tags as a XML tag when required.

                                   

                                  For example:

                                   

                                  This is a <bold>bold</bold> text and <italic>italic</italic> text.

                                   

                                  In above example character style bold and italic is used. And I need those styles as a codes before and after styled text.

                                   

                                  Please help.

                                   

                                  Thanks,

                                  Mon

                                  • 15. Re: Tagging for Character Style
                                    pkahrel Community Member

                                    < and > appear because you put them there. Instead of

                                     

                                    app.changeGrepPreferences.changeTo = "<$0>"

                                     

                                    use

                                     

                                    app.changeGrepPreferences.changeTo = "$0"

                                     

                                    Peter

                                    • 16. Re: Tagging for Character Style
                                      Velprakash Community Member

                                      I also think to say the same thing as said by peter. But u expecting the same thing mon?

                                      • 17. Re: Tagging for Character Style
                                        designmon79 Community Member

                                        But character style codes are not appear around character styles applied text. As I also mentioned above.

                                         

                                         

                                        See below screenshot which I needed

                                        Screen shot 2012-04-25 at 2.19.07 PM.png

                                         

                                        Please ignore color coding.

                                         

                                        Here I am getting with my js code

                                        Screen shot 2012-04-25 at 2.19.50 PM.png

                                         

                                        Sorry for any confusion.

                                         

                                        Thanks!

                                        Mon

                                        • 18. Re: Tagging for Character Style
                                          pkahrel Community Member

                                          Try this:

                                           

                                          styleCodes = ['Bold', 'Italic', 'Bold Italic'];
                                          styleTags = ['bold', 'italic', 'boldItalic'];
                                          
                                          app.findGrepPreferences = app.changeGrepPreferences = null;
                                          app.findGrepPreferences.findWhat = '.+';
                                          for (i = 0; i < styleCodes.length; i++)
                                              {
                                              app.findGrepPreferences.fontStyle = styleCodes[i];
                                              app.changeGrepPreferences.changeTo = '<'+styleTags[i]+'>$0<' + '/' + styleTags[i] + '>';
                                              app.activeDocument.changeGrep();
                                              }
                                          

                                           

                                          Peter

                                          • 19. Re: Tagging for Character Style
                                            designmon79 Community Member

                                            Hi Peter,

                                             

                                            Firstly, I would like to thanks for all your time and support.

                                             

                                            Your JS code is searching fontStyle defined in variable (styleCodes) whereas I need to search any appliedCharacterStyle in the document. There are lots of character style available in the document. Is there any JS code to achieve this?

                                             

                                            I also want to admit that Last year, I bought InDesign javascripting book written by you. It helps me a lot. Its great book for learner.

                                             

                                            Thanks!

                                            Mon

                                            • 20. Re: Tagging for Character Style
                                              pkahrel Community Member

                                              True, that's what you wanted:

                                               

                                               

                                              charStyles = app.activeDocument.allCharacterStyles;
                                              app.findGrepPreferences = app.changeGrepPreferences = null;
                                              app.findGrepPreferences.findWhat = '.+';
                                              // Start at 1 to skip charstyle [None]
                                              for (i = 1; i < charStyles.length; i++)
                                                  {
                                                  app.findGrepPreferences.appliedCharacterStyle = charStyles[i];
                                                  app.changeGrepPreferences.changeTo = '<'+charStyles[i].name+'>$0<' + '/' + charStyles[i].name + '>';
                                                  app.activeDocument.changeGrep();
                                                  }
                                              

                                               

                                              Peter

                                              • 21. Re: Tagging for Character Style
                                                designmon79 Community Member

                                                Hi Peter,

                                                 

                                                Its perfectly works.

                                                 

                                                I wish to thank you again for your invaluable support. You are awesome.

                                                 

                                                Thanks!

                                                Mon