4 Replies Latest reply on Feb 24, 2010 3:33 PM by mazzocchijohn

    getting AppliedCharacterStyle

    mazzocchijohn

      Hi,

       

      I have a simple question (on the face of it). I'm writing an ID CS4 script in VB6 which uses grep to perform a search & replace (styling really).

      I need to find every occurrence of pd\+ (in other words, a p followed by any number of digits) and to style the digits with the same characterstyle as the "p".

       

      What I can't work out is how to interrogate the appliedCharacterStyle applied to the "p".

       

      My search produces grep objects, which I cast to strings ... from there I can't seem to go any further. If I could nail this, the rest is pretty much done.

       

      Thanks for any help.

       

      Cheers

      John

        • 1. Re: getting AppliedCharacterStyle
          [Jongware] Most Valuable Participant
          function(){return A.apply(null,[this].concat($A(arguments)))}

          My search produces grep objects, which I cast to strings ...

           

          Actually, it doesn't, and you shouldn't (in that order).

          The list of results you get with FindGrep is sort of pointer to InDesign Text objects. You can access its contents as a string using the "contents"property, but it seems that´s unnecessary at this point.

          The objects in the FindGrep result are full Text objects, so the items can be interrogated just like you would when working immediately with, for example, a text selection. Therefore,

           

          alert (yourResultList[0].Characters.item(0).appliedCharacterStyle.name)

           

          shows the character style name of the first character only of the first found result. This is Javascript notation, by the way, but the idea should be the same.

          • 2. Re: getting AppliedCharacterStyle
            mazzocchijohn Level 1

            Thanks. That didn't work, but ...

             

            myfounditem.Words.Item(1).Characters.Item(1).AppliedCharacterStyle.Name

             

            did.

             

            myfounditem is equiv to your resultList[0], & 1s instead of 0s cos this is VB

             

            Thanks again.

            J

            • 3. Re: getting AppliedCharacterStyle
              AdobeScripts Level 3

              mazzocchijohn wrote:

               

              Thanks. That didn't work, but ...

               

              myfounditem.Words.Item(1).Characters.Item(1).AppliedCharacterStyle.Name

               

              did.

               

              myfounditem is equiv to your resultList[0], & 1s instead of 0s cos this is VB

              If your GREP is "p\d+" (not "pd\+") then your result ALWAYS will be "pXXXX" so you don't need to refer to "first word"

               

              myFoundItem.AppliedCharacterStyle = myFoundItem.Characters.Item(1).AppliedCharacterStyle

               

              robin

              www.adobescripts.com

              • 4. Re: getting AppliedCharacterStyle
                mazzocchijohn Level 1

                Hi,

                 

                thanks for that. I could've sworn that I was getting "Object required" when I wasn't specifying the first word, but I've just tried it and it works.

                Must've been soemthing else ...

                 

                Cheers

                J