3 Replies Latest reply on Aug 16, 2012 3:50 PM by [Jongware]

    Changing the style of certain words in a textbox

    KuuKuuSon

      Hi, I am completely new to Adobe scripting (new in general as I just took a class on VB in the spring) but I was interested in underlining a certain portion of content in a series of text boxes.  I have 690 serial numbers that look similar to this:

       

      TFA - 064/249 - 0753 - A

       

      I want the underlined portion shown above underline.  I have eight chapters that have their unique style so while they all have a serial number, they are in different fonts with different kerning etc (all currently with a text style applied to the text box).  Also to clarify, if it helps, the underlining doesn't always start at the same character position in every serial number.  In this example, the underlining starts at the 17th character and some might start in as little as the 14th character. 

       

      The last reference guide I did, I made a copy of the underlined portion of the data in a seperate text box, applied the style (including the underlining element), and cut and pasted each underlined portion over the ununderlined portion (as I cut and pasted every serial number into a seperate text box.

       

      Any help would be greatly appreciated and thanks in advance!

       

       

       

      p.s. Any websites with some basic tutorials on scripting would be great so I can contribute more effectively here.

       

       

       

        • 1. Re: Changing the style of certain words in a textbox
          love_all Level 1

          HI,

           

          Could you please give more clear picture on your text part because if you want to find a four digit number enclosed with hyphen is not big thing we can go with GREP option.

           

          But I feel u need more !!!!!!!!!!!

           

          Regards,

          love_all

          • 2. Re: Changing the style of certain words in a textbox
            KuuKuuSon Level 1

            My apologizes, the doctor cleared my for running after 4 and a half years and I was exhausted last night :S  I would indeed want text underlined after the hyphen but not all text.  Below are some samples of the serial numbers I am using as they are right now in my layout: 

             

            ROC - 076/132 - 1040

            TFA - 064/249 - 0753 - A

            POC - 048/048 - 1144

            CTYR - 013/039 - 1159 - A

            GIJCC - 161/178 - 1299

             

            They are each in a text box.  I would want to underline the third portion like this below:

             

            ROC - 076/132 - 1040

            TFA - 064/249 - 0753 - A

            POC - 048/048 - 1144

            CTYR - 013/039 - 1159 - A

            GIJCC - 161/178 - 1299

             

             

            Again, the serial numbers are broken into eight different series (based off the acronym in the first portion of the serial number) and therefore have eight different character styles so I'm assuming I would have to write eight scripts.  Below is a sample of what I'm working on. 

             

            _BloodfortheBaron_AM.jpg

             

            Thanks again for any help!

            • 3. Re: Changing the style of certain words in a textbox
              [Jongware] Most Valuable Participant

              KuuKuu1 wrote:

              [..] the serial numbers are broken into eight different series (based off the acronym in the first portion of the serial number) and therefore have eight different character styles so I'm assuming I would have to write eight scripts.

               

              I presume you actually mean different paragraph styles, but then again it doesn't matter. You don't have to write eight scripts, just one that can handle all cases.

               

              Still, why the need for a script? Do you have to repeat this operation regularly, on a lot of documents? It's actually very easy using a GREP style. All of the underlined numbers in your example list have four digits, and there is no other run of exactly four digits, so just create a character style that applies underlining and add this as a GREP style:

               

              \b\d{4}\b

               

              which is grepspeak for 'word boundary, digit, four times please, word boundary'.

               

              There are only two caveats attached to this method. First, since a GREP style is applied through a paragraph style, (a) you are required to use these, and (b) either you have 8 very different paragraph styles and so you need to add the GREP style to each of them in turn, or your paragraph styles are all based upon one and the same style, so you can add the GREP style to just this parent.

               

              The other caveat is that in your example list it is extremely predicatable what's to be underlined -- a run of four digits -- but your example image displays a run of three underlined digits. So one of the two examples is not a good one.

               

              If, apologies-but-you're-right, there may be three or four digits (or -- what the heck -- one or fifteen), there is still a very discerning feature about the underlined digits run. It's the last run of digits per paragraph, there aren't any more following them. (Are there?) If that's the case, you can use this slightly more complicated GREP:

               

              \b\d+(?=\D*$)

               

              (this translated exactly to the textual description of the discerning feature.)

               

              The reason I'm coaxing you to use a GREP style instead of jus' writing a script is that it's easier to use. With a script, you'd need to run it each time you add, remove, or edit your text. Besides, it's (fairly) easy to add the underlining where required, but if you edit your text and it should not be underlined anymore, you'd have to remove the underlining manually, or have a very smart script that removes it for you -- and "smart" only goes so far. (I'm thinking, if you don't have any underlining at all in the rest of your document, it might be doable to first remove all underlines, then add again where necessary.)

               

              A GREP style is part of your regular paragraph styles, so it gets saved along with your document, you can copy it into other documents, and, best of all, it's live: you will see the underlining appear and disappear whenever necessary while you are editing.