9 Replies Latest reply on Oct 12, 2016 3:12 PM by [Jongware]

    Please help me to correct my script

    HarveyLiu Level 1

      How can I make this script work?

       

      app.findGrepPreferences.findWhat = "\\[(.)";
      app.changeGrepPreferences.changeTo = "$1";
      app.findGrepPreferences.underline  = true;
      app.findGrepPreferences.underlineColor  = "underline";
      app.selection[0].changeGrep();
      app.findGrepPreferences = app.changeGrepPreferences = null;

       

      app.findGrepPreferences.findWhat = "(.)\\]";
      app.changeGrepPreferences.changeTo = "$1";
      app.findGrepPreferences.underline  = true;
      app.findGrepPreferences.underlineColor  = "underline";
      app.selection[0].changeGrep();
      app.findGrepPreferences = app.changeGrepPreferences = null;

        • 1. Re: Please help me to correct my script
          Laubender Adobe Community Professional & MVP

          Since we cannot know what you expect and what the script will do on your selection of your particular formatted text, we cannot help here…

           

          At least show some text. Before. After (expected result).

          And the results of your script of course.

           

          Best would be providing (uploading) an IDML file to a service like Dropbox so we can test.

          Lately I've seen various examples of formatted text, nested formatting with character styles, where GREP or TEXT Search/Replace is failing or yield strange results…

           

          Uwe

          • 2. Re: Please help me to correct my script
            HarveyLiu Level 1

            Hi Uwe, thank you for your response,

             

            What I want is del the square brackets, then underline the before or after character.

             

            before del square brackets like this:

             

            ASSETS

            Non-current assets

            Investments in subsidiaries                    45 [448,520]              [448,520]

            Current assets

            Amounts due from subsidiaries              17 [29,577,718]   [24,414,028]

            Other receivables and prepayments      17 [7,095]                     [3,072]

            Restricted cash                                       18 [2,786,304]      [1,033,136]

            Cash and cash equivalents                    19 [173,502]            [505,184]

                                                                                [32,544,619]   [25,955,420]

            Total assets                                               [32,993,139]     [26,403,940]

             

            I want get the result like this:

             

            ASSETS

            Non-current assets

            Investments in subsidiaries                  45          448,520         448,520

            Current assets

            Amounts due from subsidiaries            17     29,577,718     24,414,028

            Other receivables and prepayments     17             7,095              3,072

            Restricted cash                                     18     2,786,304        1,033,136

            Cash and cash equivalents                   19        173,502           505,184

                                                                                ----------------    -----------------

             

                                                                                  32,544,619     25,955,420

                                                                                ----------------    -----------------

             

            Total assets                                                  32,993,139      26,403,940

                                                                                =========    ==========

             

            and also make the underline has color, the color name: underline.

            • 3. Re: Please help me to correct my script
              Laubender Adobe Community Professional & MVP

              @HarveyLiu – I think, if you have a structure like the following one here in my screenshot, you can make it with one single paragraph style applied and a couple of clever GREP Styles using positive look behind and positive look ahead for digits: \d , brackets: \[ , \] , tabulators: \t and whole strings like: "Total assets".

               

              StructureOfTheText.png

              Put this structure to your advantage. Think in terms like:
              A digit should be underlined, if preceded by a open bracket.

               

              In GREP land this is a positive look behind from a single digit:

               

              (?<= \[)\d

               

              One hint: you can use one character style for a strike through and another character style for underline on the same character in a cascading GREP Style with a paragraph style.

               

              Another hint: you can make the brackets invisible, if you use a character style with a very small point size and fill color set to "None". Don't know, if you would need the brackets [ ] later in your workflow. So maybe it's best not to remove them.

               

              I would recommend Peter Kahrel's GREP-Editor Script for going on.

              InDesign: A simple GREP editor | Peter Kahrel

               

              TextFoundDigitsWithGrepEditor.png

               

              Uwe

              • 4. Re: Please help me to correct my script
                HarveyLiu Level 1

                I know, but I want use a script to change it,

                because, i can set a shortcut to the script,

                and no need to change two times

                and save times

                • 5. Re: Please help me to correct my script
                  Laubender Adobe Community Professional & MVP

                  I'd create one or several paragraph styles with GREP Styles and apply them through a script when the contents of the text is meeting certain creteria. You could import the paragraph styles through placing snippets out of a library file. Or copy/paste them from a different InDesign file. Or base them on the already applied paragraph style adding some GREP Styles programmatically.

                   

                  The basic thing is, that you:

                   

                  1. Make out some easy rules

                  2. Do some really basic GREPs

                  3. Do some really basic Character Styles

                  4. Do one to four paragraph styles with GREP Styles

                   

                  And stitch this all together with a script that is working on a selection, on a story or on a whole document following the made up rules in #1.

                   

                  I think it's not a good idea to remove all the brackets as a first step.
                  You'll lose an identifier for the digits you want to underline.
                  If you have to remove the brackets, do it as a final last step.

                   

                  Uwe

                  • 6. Re: Please help me to correct my script
                    HarveyLiu Level 1
                    1. I remove the square brackets not my idea it's by client request.
                    2. I'm not remove all the square brackets in the book, i do it by client need.
                    3. we are many team members work on the same job, so I can't make any style to confuse my cowokers.

                     

                    so i have to do it by manual, or by script, but in a selection

                    • 7. Re: Please help me to correct my script
                      HarveyLiu Level 1

                      app.findGrepPreferences = app.changeGrepPreferences = null;
                      app.findGrepPreferences.findWhat = "\\[(.)";
                      app.changeGrepPreferences.changeTo = "$1";
                      app.changeGrepPreferences.underline = true;
                      app.changeGrepPreferences.underlineColor = swatches.item "underline"; // <----- the script has an error in this line
                      app.selection[0].changeGrep();
                      app.findGrepPreferences = app.changeGrepPreferences = null;

                       

                      app.findGrepPreferences = app.changeGrepPreferences = null;
                      app.findGrepPreferences.findWhat = "(.)\\]";
                      app.changeGrepPreferences.changeTo = "$1";
                      app.changeGrepPreferences.underline = true;
                      app.changeGrepPreferences.underlineColor = swatches.item "underline"; // <----- the script has an error in this line
                      app.selection[0].changeGrep();
                      app.findGrepPreferences = app.changeGrepPreferences = null;

                       

                      Can someone help me to fix it?

                      • 8. Re: Please help me to correct my script
                        Skemicle Level 3

                        swatches.item("underline")

                        This might just be what you are asking for..

                        Though your first script may work if you were to place the underline in the correct GrepPreferences..

                        you have them in the find which would make the expression look for "[123,456]" instead of looking for "[123,456]" and changing to "123,456".

                         

                        And one last thing I see. You want the process to be automated to save time, but with your script you have to select each textFrame that you want changed before running the script.. You will probably want to run the changeGrep() function on the activeDocument rather than only on the first selection.

                        • 9. Re: Please help me to correct my script
                          [Jongware] Most Valuable Participant

                          For future questions:

                           

                          Please do not use non-descriptive titles such as "Correct my script please". If your question has a good title, it will be picked up easier by those who probably can answer, and it will also be easier to find for people with a similar problem.