4 Replies Latest reply on Mar 21, 2015 12:01 AM by camilo umana

    How to select a character style instead of the whole selection of text when running a script?

    camilo umana Level 1

      I have a script, that after selecting text, can modify the appearance of digits. This action, consequently, covers all the numbers in the document through:


          01. if (app.selection.length != 1)

          [... here, the rest of the script]


      How to modify this line to apply the changes only to those digits previosuly tagged with an specific character style?


      Thanks.


        • 1. Re: How to select a character style instead of the whole selection of text when running a script?
          Loic.Aigon Adobe Community Professional

          Hi,

           

          Unless I am wrong your case is a perfect candidate for Find/Change Grep.

           

          //Définition de nos critères de recherche
            app.findGrepPreferences.findWhat = "\d+";
            app.findGrepPreferences.appliedCharacterStyle = theStyle;
            app.changeGrepPreferences.changeTo = "whatever";
          
          
            //Modification du contenu
            sel.changeGrep();
          

           

          HTH,

           

          Loïc

          http://www.ozalto.com

          • 2. Re: How to select a character style instead of the whole selection of text when running a script?
            camilo umana Level 1

            Loic,

             

            Thanks. it is perfect for that situation.

            And avoids the mechanical use of f/change.

             

            What about in this case?

            I was trying to change this line that is selecting all numbers:

            if (app.selection.length != 1)

             

            It is possible to to integrate in this script by Jongware's script?

             

             

            //DESCRIPTION:omg the page numbers are all wrong!

            // A Jongware Script 18-Aug-2010

            if (app.documents.length == 0)

            {

                 alert ("Select text :'(");

                 exit(0);

            }

            if (app.selection.length != 1)

            {

                 alert ("We can't go on like this. Select some text first.");

                 exit(0);

            }

             

            myDialog = app.dialogs.add ({name:"omg the numbers are wrong!",canCancel:true});

             

            with (myDialog)

            {

                 with (dialogColumns.add())

                 {

                      with (dialogRows.add())

                           staticTexts.add ({staticLabel:"First to change"});

                      with (dialogRows.add())

                           aBox = integerEditboxes.add({editContents:"1"});

                      with (dialogRows.add())

                           staticTexts.add ({staticLabel:"Last to change"});

                      with (dialogRows.add())

                           bBox = integerEditboxes.add({editContents:"99999"});

                      with (dialogRows.add())

                           staticTexts.add ({staticLabel:"Add or subtract this value"});

                      with (dialogRows.add())

                           cBox = integerEditboxes.add({editContents:"2"});

                 }

            }

            if (!myDialog.show())

            {

                 myDialog.destroy();

                 exit(0);

            }

            first = aBox.editValue;

            last = bBox.editValue;

            step = cBox.editValue;

             

            if (first < 1 || first > last || step == 0)

            {

                 alert ("Now you're pulling my nose arentya");

                 exit(0);

            }

            app.findGrepPreferences = null;

            app.findGrepPreferences.findWhat = "\\b\\d+\\b";

            list = app.selection[0].findGrep(true);

            changes = 0;

            for (i=0; i<list.length; i++)

            {

                 n = Number(list[i].contents);

                 if (n >= first && n <= last)

                      changes++, list[i].contents = String(n+step);

            }

            alert ("Number of changes: "+changes);

            • 3. Re: How to select a character style instead of the whole selection of text when running a script?
              Loic.Aigon Adobe Community Professional

              I was trying to change this line that is selecting all numbers:

              if (app.selection.length != 1)

              This line does all but selecting all numbers. It just checks if there are more than one item selected. Texts selection always return length of 1. Hence this check.

               

              And given what I offered previously, all you should have to do in Jongware script to match your needs is to add app.findGrepPreferences.appliedCharacterStyle = theStyle; 

              Prior to findGrep().

               

              HTH

               

              Loic

              http://www.ozalto.com

              • 4. Re: How to select a character style instead of the whole selection of text when running a script?
                camilo umana Level 1

                Loic, thanks a lot.

                Now it is possible in a TOC change only the page numbers, specially when the body has dates or chyphers.