6 Replies Latest reply on Feb 15, 2013 10:06 AM by MrTIFF

    Change UnderlineStrokeWeight

    shilpa25 Level 1

      Hi Forum,


      How do i change Underline Storke weight less than 0.5pt to 0.5pt and not to change above 0.5pt.


      Any help on this... Please.




        • 1. Re: Change UnderlineStrokeWeight
          Vamitul Level 4

          here you go:


          function main(){
          function resetOpt() {
            var old_fCGOpts = app.findChangeGrepOptions.properties;
            var old_fGPref = app.findGrepPreferences.properties;
            var old_cGPref = app.changeGrepPreferences.properties;
            app.findChangeGrepOptions = NothingEnum.NOTHING;
            app.findGrepPreferences = NothingEnum.NOTHING;
            app.changeGrepPreferences = NothingEnum.NOTHING;
            return [old_fCGOpts, old_fGPref, old_cGPref]
          function restoreOpt(myOpt) {
            app.findChangeGrepOptions.properties = myOpt[0];
            app.findGrepPreferences.properties = myOpt[1];
            app.changeGrepPreferences.properties = myOpt[2];
              var myOpt=resetOpt ();
              var myRes=app.activeDocument.findGrep(), l=myRes.length;
              while (l--){
                  if (myRes[l].underlineWeight<0.5){
          restoreOpt (myOpt);
          app.doScript('main()', undefined, undefined, UndoModes.entireScript, 'Fix Underline');
          • 2. Re: Change UnderlineStrokeWeight
            shilpa25 Level 1

            fantabulous Vam!..


            I struggled a lot in doing it..


            Can I ask  a Questions.


            what is Fix Underline(); How does the extenscript understand this.




            • 3. Re: Change UnderlineStrokeWeight
              Vamitul Level 4

              you mean the doScript part? It's just so you have a single undo point.


              basicly the script works like this:

              1) saves the 'state' of your Find Change Grep dialog (i find it annoying when some script messes with it);

              2) finds every underline piece of text 

              3) test each one to see if the weight of the underline is smaller that 0.5. if it is it changes it to 0.5

              4) restore the find change grep dialog.



              1 person found this helpful
              • 4. Re: Change UnderlineStrokeWeight
                shilpa25 Level 1

                Very Helpful hint Vam,


                thanks a lot...

                • 5. Re: Change UnderlineStrokeWeight
                  MrTIFF Level 3

                  @Vamitul - So I made some underlined text (via the UI), and I'm stepping through the script in the ESTK ... it's telling me that myRes[l].underlineWeight is -9999.  What's up with that? So, the test always returns true, and I'm setting ALL underlines to a weight of 0.5.

                  • 6. Re: Change UnderlineStrokeWeight
                    MrTIFF Level 3

                    @self - ah, I see ... if nothing has set the underlineWeight explicitly, either in a text override or app or doc textDefaults, then underlineWeight will be -9999, and InDesign just makes up an underlineWeight "on the fly" based on the font size, by dividing the font size by 20. So, to be safe, I guess the script should check myRes[l].underlineWeight for -9999, and if that is true, then compute the "effectiveUnderlineWeight" to 1/20 of the font size, and then compare THAT to 0.5. Whew. Is there an easier way?