12 Replies Latest reply on Apr 17, 2014 11:45 AM by Kai Rübsamen

    Tagging italics question

    davidnest Level 1

      I've created two grep queries that I use to tag the italics of placed text. Then I manually apply the Basic Paragraph clear overides style. Then I run another Grep querry that takes the words and sentences that have the tags and applies an italic style that I created in the Character style pallet. Here is my Grep Querry for find and Tag italics.

       

      Find What:

      (.+)

       

      Change to:

      [i]$1[/i]

       

      Find Format:

      +Italic

       

      Here is My Querry for appling italic character style to tagged text.

       

      Find What:

      (\[\i\])(.+?)(\[/\i\])

       

      Change to:

      $2

       

      What I'm wondering is if this all could be run from a javascript including applying the Basic Paragraph clear overrides part. I'm not sure where to even begin as I'm new to scripting. Any help would be very appriciated. Thanks.

        • 1. Re: Tagging italics question
          Kai Rübsamen Adobe Community Professional

          Hi,

           

          I did not understand, why you tag your italics first, then apply a paragraph style, remove the overrides and then search for tags and apply your character style.

           

          If you do this in the interface, the first step would be search for italics, apply a character style, then apply your pStyle and remove only the local overrides.

           

          Select a frame and try the following lines:

           

           

          var curSel = app.selection[0];
          
          app.findGrepPreferences = app.changeGrepPreferences = null;
          app.findGrepPreferences.fontStyle = "Italic";
          app.changeGrepPreferences.appliedCharacterStyle = "italic";
          
          curSel.changeGrep();
          
          curSel.paragraphs.everyItem().appliedParagraphStyle = "myPStyle";
          
          • 2. Re: Tagging italics question
            davidnest Level 1

            Pasting word files into InDesign on a Mac sometimes causes strange font issues so tagging the italics allows me to wipe out all formatting on the text. Then I can process the text without losing the location of the italics. 

             

             

            Thanks for this. I'll test it out.

            • 3. Re: Tagging italics question
              davidnest Level 1

              So this seems to be working. Now would it be possible to automaticly create the two styles "italics in character styles and "Body" in Paragraph styles?

              • 4. Re: Tagging italics question
                davidnest Level 1

                ok. So I'm able to create the styles and I'm getting close to what I need. One last thing. How can I check to see if the character and Body styles exist allready. If they do move on to appling the styles if not create them. Here is the script, anyone out there know how to do this? I'm thinking its try{} but I'm not having any luck. Thanks.

                 

                pStyle = app.activeDocument.paragraphStyles .add({name:"Body"})

                app.activeDocument.characterStyles.add({name:"italics"});

                 

                 

                var curSel = app.selection[0];

                 

                app.findGrepPreferences = app.changeGrepPreferences = null;

                app.findGrepPreferences.fontStyle = "Italic";

                app.changeGrepPreferences.appliedCharacterStyle = "italics";

                 

                curSel.changeGrep();

                 

                curSel.paragraphs.everyItem().appliedParagraphStyle = "Body";

                • 5. Re: Tagging italics question
                  Jump_Over Level 5

                  Hi,

                   

                  Check if mentioned style.isValid before define it:

                  if ( !app.activeDocument.paragraphStyle.item("Body").isValid )
                            app.activeDocument.paragraphStyles .add({name:"Body"});
                  if ( !app.activeDocument.characterStyles.item("italics").isValid )
                            app.activeDocument.characterStyles.add({name:"italics"});
                  //...
                  

                  Jarek

                  • 6. Re: Tagging italics question
                    Kai Rübsamen Adobe Community Professional

                    David, if your styles are not valid, you must provide also some font-information.

                     

                     

                    var curDoc = app.activeDocument;
                    var curSel = app.selection[0];
                    
                    if (!curDoc.characterStyles.item("italic").isValid) {
                        var cStyle = curDoc.characterStyles.add({name: "italic"});
                    }
                    else {
                        var cStyle = curDoc.characterStyles.item("italic");
                    }
                    
                    cStyle.fontStyle = "Italic";
                    
                    app.findGrepPreferences = app.changeGrepPreferences = null;
                    app.findGrepPreferences.fontStyle = "Italic";
                    app.changeGrepPreferences.appliedCharacterStyle = cStyle;
                    
                    curSel.changeGrep();
                    
                    
                    if (!curDoc.paragraphStyles.item("body").isValid) {
                        var pStyle = curDoc.paragraphStyles.add({name: "body"});
                    }
                    else {
                        var pStyle = curDoc.paragraphStyles.item("body");
                    }
                    
                    with (pStyle) {
                        appliedFont = "Myriad Pro\tRegular";
                        pointSize = 11.5;
                        fillColor = "Black";
                    }
                    
                    curSel.paragraphs.everyItem().appliedParagraphStyle = pStyle;
                    
                    • 7. Re: Tagging italics question
                      davidnest Level 1

                      This script is excellent but it does one thing that I do not want. When its used multiple times in the same doc and changes have been made to the italics it overrides them and sets it back to italics. For example: if the italics character fontStyle is changed to oblique because that what the font has it sets it back to italic. Would there be a way to set it so that if the italics does exist in the character pallet then do not change it, else...?

                      • 8. Re: Tagging italics question
                        Kai Rübsamen Adobe Community Professional

                        David, did not understand, what is your goal! Maybe it is to early in the morning or more information is needed ;-)

                         

                        If you make some changes to a part with a italic character style, you make some local overrides. If you run the script again, those characters will not be found anymore, because the fontstyle is not "italics" anymore.

                         

                        But: If your apply your paragraph style, all overrides will be removed, and you get in the endresult: italics!

                        • 9. Re: Tagging italics question
                          davidnest Level 1

                          Sorry for the confusion, thanks for replying back! I trying to learn scripting for indesign and its a steep curve, so thanks for any help.

                           

                          Basically the issue is when a font typeface uses a different naming convention like, oblique, or 57 oblique instead of italics. After I run the script once and it creates the body paragraph style and the italics character style, I usually go into the paragraph style and change it to the font I need, if that font uses oblique instead of italics I have to go into the italics character style and change it to oblique. Now when I get some new text in, I select it and run the script, instead of just seeing that the italics style already exists and apply it, it sets it back to fontStyle italics and overrides the oblique change I made to the italics character style. I was just wondering if there is some way to keep my local oblique change to the italics character style when I process new text?

                          • 10. Re: Tagging italics question
                            Kai Rübsamen Adobe Community Professional

                            I trying to learn scripting for indesign

                            me too

                             

                            First of all, it is always a good idea, to know, what a script does. Second, it is a good idea, to have a good workflow. I’m not sure, if I would do it in your way, but let us find a solution for the first one:

                             

                            The script does, what you have ordered: At first it stores your selection. Then it check, if the paragraph style and the character style is available. If not, the script will create them.

                             

                            Here comes the problem: It does not matter, if the para- or characterStyle is in the document, in every case the font information is set to new values. So a solution might be to set the new values only if the styles are not in the document.

                             

                            btw to your workflow: Instead of changing you styles by hand in the ui, you could also set those parameters in the script.

                             

                            The following version will not set the attributes back, if you edit them once.

                             

                             

                            var curDoc = app.activeDocument;
                            var curSel = app.selection[0];
                            
                            if (!curDoc.characterStyles.item("italic").isValid) {
                                var cStyle = curDoc.characterStyles.add({name: "italic"});
                                cStyle.fontStyle = "Italic";
                            }
                            else {
                                var cStyle = curDoc.characterStyles.item("italic");
                            }
                              
                            app.findGrepPreferences = app.changeGrepPreferences = null;
                            app.findGrepPreferences.fontStyle = "Italic";
                            app.changeGrepPreferences.appliedCharacterStyle = cStyle;
                            
                            curSel.changeGrep();
                            
                            
                            if (!curDoc.paragraphStyles.item("body").isValid) {
                                var pStyle = curDoc.paragraphStyles.add({name: "body"});
                                with (pStyle) {
                                    appliedFont = "Myriad Pro\tRegular";
                                    pointSize = 11.5;
                                    fillColor = "Black";
                                }
                            }
                            else {
                                var pStyle = curDoc.paragraphStyles.item("body");
                            }
                            
                            curSel.paragraphs.everyItem().appliedParagraphStyle = pStyle;
                            
                            • 11. Re: Tagging italics question
                              davidnest Level 1

                              So it works. So what you did was pull the style changes up into the if condition and that sets those parameter only if it doesn't exist?

                              You mention in your last post that you wouldn't do it this way, what changes would you make? I'm just curious to get a perspective on this.

                               

                               

                              Thanks again.

                              • 12. Re: Tagging italics question
                                Kai Rübsamen Adobe Community Professional

                                yes! If the style does not exist, create it and set the properties, else if the style exists simply use it.

                                 

                                To your second question: That depends really on your workflow: I would think that you have a template with your p and c styles and simply call them in the script. If you can define rules for your paragraphs and characters, you can apply more than "body" and "italic", for example headings, subheadings, headings between, bold, underline …

                                 

                                On the other hand: You could also define your styles in the script as shown in the part that begins with "with".

                                 

                                Whatever your solution is: I would never run a script and then change the attributes of paragraph and character styles later by hand. It should match either previously or the script should do that work.

                                 

                                best

                                Kai