10 Replies Latest reply on Jul 2, 2014 11:33 PM by hasvi

    Insert numbers in order by script

    hasvi Level 1

      Hi,

       

      My indesign file has 'AQ' character style, now I want to add the numbers in order 1, 2,3,... instead of 'AQ' character style. Is this possible by script?

       

      Before process:

      1.png

      After process:

      2.png

      by hasvi

        • 1. Re: Insert numbers in order by script
          Kai Rübsamen Adobe Community Professional

          It is not clear, what is the goal here!

           

          Your before screens shows number 1,2,3 already. Your after screen shows numbers without space after or before ??

           

          To delete everything without your numbers, you can use a simple grep:

          Find: <AQ: Please see (\d+)>

          Change $1

           

          –Kai

          • 2. Re: Insert numbers in order by script
            hasvi Level 1

            Hi,

             

            I am going to fix the 'Author Query Number' instead of 'Author Query Text'. Here I used AQ-character style for 'Author Query Text', after insert 'Author Query Number' I am going to change my character style from 'AQ' to 'Superscript'. Is this possible by script?

             

             

            Author Query Text:

            1.png

             

             

            Author Query Number:

            2.png

             

            by

            hasvi

            • 3. Re: Insert numbers in order by script
              Kai Rübsamen Adobe Community Professional

              Your screens show now different things than before, hm

               

              In your first new screen, there is no number anymore. So I assume, that the text should be deleted, the script should insert 1,2,3 and apply a character style superscript?

              But in your second screen the number is not at the same position. Instead the number moves to the beginning of a sentence?

               

              Your screens are very helpful. But not, of they show different things and not if the explanation understandable.

              • 4. Re: Insert numbers in order by script
                hasvi Level 1

                Hi,

                 

                your first point is correct: "In your first new screen, there is no number anymore. So I assume, that the text should be deleted, the script should insert 1,2,3 and apply a character style superscript?"

                 

                Sorry for my second screenshot I have insert the 1st number in wrong position. Your understand is correct on your first para.

                 

                by

                hasvi

                • 5. Re: Re: Insert numbers in order by script
                  Kai Rübsamen Adobe Community Professional

                  Hasvi, it is maybe very clear for you, what your goal is. But sadly, I do not understand it.

                   

                  Try this one:

                   

                  app.findTextPreferences = app.changeTextPreferences = null;   
                  app.findTextPreferences.findWhat = "<AQ: Please see page number>";
                  var allFound = app.activeDocument.findText();   
                     
                  for( var n = allFound.length; n > 0; n-- )  {  
                      var curFound = allFound[n-1];
                      curFound.appliedCharacterStyle = "superscript";
                      curFound.contents = n.toString();         
                  } 
                  

                   

                  –Kai

                  • 6. Re: Insert numbers in order by script
                    hasvi Level 1

                    Hi Kai,

                     

                    I have to find the text within(less than and greater than symbol) "<...>".

                    <AQ: Please see page number>: Here I want to find within less than and greater than symbol text, that text may contain symbols or numbers anything, but I need to find within less than and greater than symbol text. What is the Grep for this?

                     

                    by

                    hasvi

                    • 7. Re: Insert numbers in order by script
                      Chinnadk Level 4

                      Try this,

                       

                      (?<=<)(.*?)(?=>)

                       

                      Regards,

                      Chinna

                      • 8. Re: Insert numbers in order by script
                        hasvi Level 1

                        Hi,

                         

                        Can we get the log report for "<AQ: Please see page number>" text detail as a doc file. For instance I have applied character style 'Query' for <AQ: Please see page number>. Collect all character style 'Query' then create the log report as a doc file. Is this possible?

                         

                        by

                        hasvi

                        • 9. Re: Re: Insert numbers in order by script
                          Chinnadk Level 4

                          Try this,

                           

                          var doc = app.activeDocument;
                          app.findGrepPreferences = app.changeGrepPreferences = null;
                          app.findGrepPreferences.findWhat = "(?<=<)(.*?)(?=>)";
                          var found = doc.findGrep();
                          app.findGrepPreferences = app.changeGrepPreferences = null;
                          var _text = ""
                          for(var i =0;i<found.length;i++)
                          {
                                  _text += found[i].contents + "\r";
                              }
                          alert(_text);
                          

                           

                          Regards,

                          Chinna

                          • 10. Re: Re: Insert numbers in order by script
                            hasvi Level 1

                            Hi chinna,

                             

                            I got the log report from your script, but my bold, italic details are missing in log report, is there any possible to get the bold, italic details from "app.findGrepPreferences.findWhat = "(?<=<)(.*?)(?=>)";"  

                            var doc = app.activeDocument; 

                            app.findGrepPreferences = app.changeGrepPreferences = null; 

                            app.findGrepPreferences.findWhat = "(?<=<)(.*?)(?=>)"; 

                            var found = doc.findGrep(); 

                            app.findGrepPreferences = app.changeGrepPreferences = null; 

                            var _text = "" 

                            for(var i =0;i<found.length;i++) 

                                    _text += found[i].contents + "\r"; 

                                } 

                            //~ alert(_text); 

                             

                             

                            var file = new File("~/Desktop/report.doc");

                                file.open("w");

                                file.write(_text);

                                file.close();

                             

                            by

                            hasvi