6 Replies Latest reply on Sep 7, 2014 11:22 PM by Laubender

    How can i insert the insertion point in each paragraph first

    NithinMNK

      Hi all

       

      Please find the below script, this script place the insertion point in end of the each paragraph, but i need to place the insertion point in first letter of the each paragraph. Please help.

       

       

      var myDoc=app.documents.item(0)

      var myLib=app.libraries.item(0)

      app.findTextPreferences=null;

      app.changeTextPreferences=null;

      app.findChangeTextOptions.caseSensitive=false;

      app.findChangeTextOptions.includeFootnotes=false;

      app.findTextPreferences.appliedParagraphStyle="TX"

      app.findTextPreferences.findWhat="^p"

      var myFinds=myDoc.findText()

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

      {

      var myIcon=myLib.assets.item("Para").placeAsset(myFinds[i].insertionPoints[0])[0]

      myIcon.appliedObjectStyle=myDoc.objectStyles.item("Para No")

      }

       

      Thanks & Regards

      Nithin

        • 1. Re: How can i insert the insertion point in each paragraph first
          Sajeev Sridharan Level 4

          Try Grep,

           

          var myDoc=app.documents.item(0)
          var myLib=app.libraries.item(0)
          app.findGrepPreferences=app.changeGrepPreferences=null;  
          app.findGrepPreferences.findWhat=".+\\r"
          app.findGrepPreferences.appliedParagraphStyle="TX"
          var myFinds=myDoc.findGrep()
          for(i=0; i<myFinds.length; i++)
          {
              myFinds[i].select();
              myFinds[i].insertionPoints[0].select();
          }
           app.findGrepPreferences=app.changeGrepPreferences=null;  
          

           

           

          Vandy

          • 2. Re: How can i insert the insertion point in each paragraph first
            Chinnadk Level 4

            Hi Nithin,

             

            Try this,

             

            var doc = app.activeDocument,
                myLib=app.libraries.item(0),
                _paragraphs = doc.stories.everyItem().paragraphs.everyItem().getElements(), i;
              
            for(i =_paragraphs.length-1;i>=0;i--)
            {
                    if(_paragraphs[i].appliedParagraphStyle.name == "TX")
                    {
                            var myIcon=myLib.assets.item("Para").placeAsset(_paragraphs[i].insertionPoints[0])[0];
                            myIcon.appliedObjectStyle=doc.objectStyles.item("Para No")
                        }
                }
            

             

             

            Regards,

            Chinna

            • 3. Re: How can i insert the insertion point in each paragraph first
              NithinMNK Level 1

              Hi Vandy

               

              Thanks for your help, if am using the script, the anchor object is placed in First paragraph in first and the other paragraphs in end of the line. Find below the screenshot.

              Screen Shot 2014-09-08 at 10.47.10 AM.png

              For your kind information, am using the below script:

               

              var myDoc=app.documents.item(0)

              var myLib=app.libraries.item(0)

              app.findGrepPreferences=null;

              app.changeGrepPreferences=null;

              app.findChangeGrepOptions.includeFootnotes=false;

              app.findGrepPreferences.appliedParagraphStyle="TX"

              app.findGrepPreferences.findWhat=".+\\r"

              var myFinds=myDoc.findGrep()

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

              {

              var myIcon=myLib.assets.item("Para").placeAsset(myFinds[i].insertionPoints[0])[0]

              myIcon.appliedObjectStyle=myDoc.objectStyles.item("Para No")

              }

               

              Please help me.

               

              Thanks & Regards

              Nithin

              • 4. Re: How can i insert the insertion point in each paragraph first
                Sajeev Sridharan Level 4

                Could you please show me the input and output clearly in a screenshot

                 

                Vandy

                • 5. Re: How can i insert the insertion point in each paragraph first
                  Chinnadk Level 4

                  After inserting the first item, the insertion points of the remaining item have shifted so use reverse loop or try my above script .

                  • 6. Re: Re: How can i insert the insertion point in each paragraph first
                    Laubender Adobe Community Professional & MVP

                    @Nithin – inserting the anchor by placing the asset is changing the position of the next anchor, because the script's for-loop is running from the first found instance to the last found one.

                     

                    If you go through all the found instances from back to forth would be one solution.

                     

                    var myDoc=app.documents.item(0)
                    var myLib=app.libraries.item(0)
                    app.findGrepPreferences=null;
                    app.changeGrepPreferences=null;
                    app.findChangeGrepOptions.includeFootnotes=false;
                    app.findGrepPreferences.appliedParagraphStyle="TX"
                    app.findGrepPreferences.findWhat=".+\\r"
                    var myFinds=myDoc.findGrep()
                    
                    for(i=myFinds.length-1; i>=0; i--)
                    {
                    var myIcon=myLib.assets.item("Para").placeAsset(myFinds[i].insertionPoints[0])[0]
                    myIcon.appliedObjectStyle=myDoc.objectStyles.item("Para No")
                    }
                    

                     

                    Another one would be doing the search from back to forth and not changing the for-loop:

                     

                    var myFinds=myDoc.findGrep(true);
                    

                     

                    Array of Text findGrep ([reverseOrder: bool])

                    Finds text that matches the find what value.

                     

                     

                    Uwe