18 Replies Latest reply on Jun 3, 2011 5:52 AM by Kasyan Servetsky

    Cleaning up script

    LouisHectorMonty Level 1

      Hello All

       

      We often translate indesign files using a CAT tool to open the idml file. But most of the InDesign files we are sent have been created by people who take a great many short cuts to get things to fit, which maybe good for them but not for us.

       

      We need a script that can set all kerning to 0 or a constant value throughout a document, remove all stretched text and change any thing with ALL CAPS to true uppercase.

       

      There are a few more niggly things we have to do to clean it up which can take a few hours for a large document so it would be good it there was a script that could do this or if anyone knows how to create one for us we would be happy to work with you to create it.

        • 1. Re: Cleaning up script
          Kasyan Servetsky Level 5

          Here is a simple script to get you started:

          const kerningConstant = 0;
          var doc = app.activeDocument,
          stories = doc.stories,
          story, text, s, t;
          
          for (var s = 0; s < stories.length; s++) {
               story = stories[s];
               for (var t = 0; t < story.texts.length; t++) {
                    text = story.texts[t];
                    text.kerningValue = kerningConstant;
                    text.verticalScale = 100;
                    text.horizontalScale = 100;
               }
          }
          

           

          It's not clear to me what you do with ALL CAPS in InDesign — do you turn them off and retype the text manually with Caps Lock on?

           

          Regards,

          Kas

          1 person found this helpful
          • 2. Re: Cleaning up script
            LouisHectorMonty Level 1

            Hi Kas

             

            Thanks for that, I shall try it out.

             

            When we come across text that is using the 'ALL CAPS' control we select the text and turn this off, then use a shortcut to convert to uppercase, using the type/change case/uppercase command.

             

            The problem is when we upload to our CAT tool everytime there is a change to the formating in a word then 'tags' are inserted where a change begins and ends, so if a designer has been mucking about with kerning, tracking, scaling text etc or has been using "ALL CAPS" on some letters and not on others (yes we can have half a word in All CAPS and half in true uppercase!) then text can look like this to the translator.

             

             

            T*h**is i**s v*e**ry d*i*ffi**cu*lt to* re*ad *text*

             

            As we typeset the text after translation in InDesign we add our own tweaks where necessary.

            • 3. Re: Cleaning up script
              Kasyan Servetsky Level 5

              OK. I see now: we can use the changecase method.

              • 4. Re: Cleaning up script
                Kasyan Servetsky Level 5

                Here is a new version:

                const kerningConstant = 0;
                var doc = app.activeDocument,
                stories = doc.stories,
                story, text, s, t;
                
                for (var s = 0; s < stories.length; s++) {
                     story = stories[s];
                     for (var t = 0; t < story.texts.length; t++) {
                          text = story.texts[t];
                          text.kerningValue = kerningConstant;
                          text.verticalScale = 100;
                          text.horizontalScale = 100;
                          ChangeCase(text);
                     }
                }
                
                function ChangeCase(text) {
                     var i, found;
                     if (text.contents != "") {
                          app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
                          app.findGrepPreferences.findWhat = ".+";
                          app.findGrepPreferences.capitalization = Capitalization.ALL_CAPS;
                          var found = text.findGrep();
                          if (found.length > 1) {
                               for (i = 0; i < found.length; i++) {
                                    // $.writeln( i + " - " + found[i].constructor.name + "/"+ found[i].contents );
                                    found[i].changecase(ChangecaseMode.UPPERCASE);
                               }
                               app.changeGrepPreferences.capitalization = Capitalization.NORMAL;
                               text.changeGrep();
                          }     
                     }
                }
                
                • 5. Re: Cleaning up script
                  LouisHectorMonty Level 1

                  Hi Kas

                   

                  Ok, my scripting abilities are pretty non existent, I copied the script and pasted it into a text doc and saved it with .jsx on the end and save it to the scripts folder. It shows up in InDesign but does not do anything, what did I do wrong?

                  • 6. Re: Cleaning up script
                    LouisHectorMonty Level 1

                    tell a lie...it did change kerning to 0 and the scaling to 100% but the caps did not change to uppercase. I am assuming these are dfferent things.

                     

                    Can you add tracking to that mix as well, tracking to 0.

                    • 7. Re: Cleaning up script
                      Kasyan Servetsky Level 5

                      The script should be in the Scripts Panel folder, not Scripts.

                      This version is very basic so it doesn't do any error testing: e.g. if a document is open, etc. You also haven't mentioned which version of ID you use; I wrote this for CS5.

                      • 8. Re: Cleaning up script
                        Kasyan Servetsky Level 5

                        Can you add tracking to that mix as well, tracking to 0.

                        text.tracking = 0;
                        

                        I think this line should do the job.

                        1 person found this helpful
                        • 9. Re: Cleaning up script
                          LouisHectorMonty Level 1

                          Hi Kas

                           

                          Added that line and it works, amazed myself. The only but that does not is the caps bit.

                           

                          Does this script work on the whole document or just the story, text box you are in?

                          • 10. Re: Cleaning up script
                            Kasyan Servetsky Level 5

                            Let's try this version.

                            const kerningConstant = 0;
                            var doc = app.activeDocument,
                            stories = doc.stories,
                            story, text, found, s, t, i;
                            
                            for (var s = 0; s < stories.length; s++) {
                                 story = stories[s];
                                 for (var t = 0; t < story.texts.length; t++) {
                                      text = story.texts[t];
                                      text.kerningValue = kerningConstant;
                                      text.verticalScale = 100;
                                      text.horizontalScale = 100;
                                      text.tracking = 0;
                                 }
                            }
                            
                            app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
                            app.findGrepPreferences.findWhat = ".+";
                            app.findGrepPreferences.capitalization = Capitalization.ALL_CAPS;
                            found = doc.findGrep();
                            if (found.length > 1) {
                                 for (i = 0; i < found.length; i++) {
                                      //$.writeln( i + " - " + found[i].constructor.name + "/"+ found[i].contents );
                                      found[i].changecase(ChangecaseMode.UPPERCASE);
                                 }
                                 app.changeGrepPreferences.capitalization = Capitalization.NORMAL;
                                 doc.changeGrep();
                            }
                            
                            • 11. Re: Cleaning up script
                              Kasyan Servetsky Level 5

                              Here I posted a couple of samples: before and after running the script. Try to run it against the 'before' sample.

                              • 12. Re: Cleaning up script
                                John Hawkinson Level 5
                                The problem is when we upload to our CAT tool everytime there is a change to the formating in a word then 'tags' are inserted where a change begins and ends, so if a designer has been mucking about with kerning, tracking, scaling text etc or has been using "ALL CAPS" on some letters and not on others (yes we can have half a word in All CAPS and half in true uppercase!) then text can look like this to the translator.

                                You do realize that trying to solve this problem in InDesign is not the right solution.

                                You will forever have these kinds of problems.

                                 

                                The right answer is to postprocess the IDML, such as with XSLT, and remove the extraneous tags.

                                 

                                What does your CAT tool look at? Does it just look at the <Content/> tags inside the story files, or is it more complicated?

                                Do you care about paragraph breaks?

                                • 13. Re: Cleaning up script
                                  LouisHectorMonty Level 1

                                  Hi Kas

                                   

                                  That worked perfectly....

                                   

                                  Many thanks for your help, I shall be incontact outside of this forum if we need your expertise again.

                                  • 14. Re: Cleaning up script
                                    LouisHectorMonty Level 1

                                    Thanks for the response, but this is the right way to go for us. Tried and tested, we just needed to automate it.

                                    • 15. Re: Cleaning up script
                                      John Hawkinson Level 5

                                      OK, well, when you start having more problems because of other kinds of formatting and overrides, please reconsider. If so, answers to the questions above would be a good start at making it work. It's probably not too difficult, either.

                                       

                                      Though thinking some more, I have to wonder why you start with IDML if your translation is not really about formatting -- it would seem like exporting to text would just work better...unless you have a lot of stories? Even so...

                                      • 16. Re: Cleaning up script
                                        LouisHectorMonty Level 1

                                        Hi John

                                         

                                        We use a CAT tool called XTM which enables us to upload an idml file. When the translator starts translating all they see is the text with [1]tags like this,[1] [2] this denotes different formatting[2]. If we do not take out the superfluous formatting the translator sees lots of tags inbetween letters of words, which makes for slower translation and a complaining translator!

                                         

                                        Some formatting is obviously left as is, so when the idml file is downloaded all the text is translated with major formatting remaining so there is very little tidying up to do.

                                         

                                        The formatting we are changing is usually only used to fit the source text by the designer and is irrelevant to us as the target text is normally about 20-30% longer.

                                        • 17. Re: Cleaning up script
                                          LouisHectorMonty Level 1

                                          Hi Kas

                                           

                                          Just realised the text which was all caps was unaffected by the commands to set kerning to 0, was this because of the order the script is carried out in?

                                          • 18. Re: Cleaning up script
                                            Kasyan Servetsky Level 5

                                            Just realised the text which was all caps was unaffected by the commands to set kerning to 0, was this because of the order the script is carried out in?

                                            Yes, it was. Here's a new version:

                                            const kerningConstant = 0;
                                            var doc = app.activeDocument,
                                            stories = doc.stories,
                                            story, text, found, s, t, i;
                                            
                                            app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
                                            app.findGrepPreferences.findWhat = ".+";
                                            app.findGrepPreferences.capitalization = Capitalization.ALL_CAPS;
                                            found = doc.findGrep();
                                            if (found.length > 0) {
                                                 for (i = 0; i < found.length; i++) {
                                                      //$.writeln( i + " - " + found[i].constructor.name + "/"+ found[i].contents );
                                                      found[i].changecase(ChangecaseMode.UPPERCASE);
                                                 }
                                                 app.changeGrepPreferences.capitalization = Capitalization.NORMAL;
                                                 doc.changeGrep();
                                            }
                                            
                                            for (var s = 0; s < stories.length; s++) {
                                                 story = stories[s];
                                                 for (var t = 0; t < story.texts.length; t++) {
                                                      text = story.texts[t];
                                                      text.kerningValue = kerningConstant;
                                                      text.verticalScale = 100;
                                                      text.horizontalScale = 100;
                                                      text.tracking = 0;
                                                 }
                                            }