4 Replies Latest reply on Dec 2, 2013 1:29 AM by BEGINNER_X

    Line count Help

    BEGINNER_X Level 3

      Hi All,

       

      Please help to alert the 5th, 10th, 15th, 20th line contents.

       

      Condition is, if the 5th, 10th, 15th, 20th line should H1, Equation1, Equation2, Equation3 then script alert the next line.

       

      Please HELP.

       

      Please refer screenshot

       

      Screen Shot 2013-12-02 at 12.06.13 PM.png

       

      Trying Script:

       

       

      var myDoc = app.activeDocument;
      
      var myLib = app.libraries[0];
      
      
      var myLines = app.activeDocument.stories.everyItem().lines.everyItem().getElements();
      
      //~ var myLines = app.selection[0].parentStory.lines;
      
      
      
      for(i=4; i<myLines.length; i = i+5)
      {
         if(myLines[i].appliedParagraphStyle.name == "H1" || myLines[i].appliedParagraphStyle.name == "Equation1")
          {
               i = i+1;
                 }
            if(myLines[i].appliedParagraphStyle.name == "H1" || myLines[i].appliedParagraphStyle.name == "Equation1")
              {
                  i= i+1;
                  }
             if(myLines[i].appliedParagraphStyle.name == "H1" || myLines[i].appliedParagraphStyle.name == "Equation1")
              {
                  i= i+1;
                  }
             if(myLines[i].appliedParagraphStyle.name == "H1"|| myLines[i].appliedParagraphStyle.name == "Equation1")
              {
                  i= i+1;
                  }
      
         var temp = myLines[i].contents;
      
         alert(temp)
      
            myText = myLib.assets.item("LN").placeAsset(myLines[i].insertionPoints[0])[0];
      
            myText.appliedObjectStyle = app.activeDocument.objectStyles.item("LN_OBJ_STY");
      
            myText.insertionPoints[0].contents = i;
      
      
          }
      

       

      Could anyone please help

       

      Thanks in advance

      Beginner_X

        • 1. Re: Line count Help
          Jump_Over Level 5

          Hi,

           

          maybe this way:

           

          var 
                    myDoc = app.activeDocument,
                    myLib = app.libraries[0],
                    myLines = app.activeDocument.stories.everyItem().lines.everyItem().getElements(),
                    i;
          
          for(i = 4; i < myLines.length; i = i + 5) {
                       if(myLines[i].appliedParagraphStyle.name == "H1" ||
                                      myLines[i].appliedParagraphStyle.name == "Equation1" ||
                                      myLines[i].appliedParagraphStyle.name == "Equation2" ||
                                      myLines[i].appliedParagraphStyle.name == "Equation3")
                     {
                                      mProcess (i+1);
                                      }
                       }
          function mProcess (lineIdx) {
               alert (myLines[lineIdx].contents);
          
               var myText = myLib.assets.item("LN").placeAsset(myLines[lineIdx].insertionPoints[0])[0];
               myText.appliedObjectStyle = app.activeDocument.objectStyles.item("LN_OBJ_STY");
               myText.insertionPoints[0].contents = lineIdx;
               }
          

           

          Jarek

          1 person found this helpful
          • 2. Re: Line count Help
            BEGINNER_X Level 3

            Hi Jump_Over,

             

            Thank you for your immediate response....

             

            With the help of my senior I got the below line, it works great but I struggle in single line..

             

            myText.insertionPoints[0].contents = "hi";   //I need line count 5, 10 ++++

             

             

             

            var myDoc = app.activeDocument;
            
            var myLib = app.libraries[0];
            
            var myArray = new Array;
            
            var myLines = app.activeDocument.stories.everyItem().lines.everyItem().getElements();
            
            //~ var myLines = app.selection[0].parentStory.lines;
            
            
            n = 4;
            for(i=4; i<myLines.length; i++)
            {
                 if(myLines[i].appliedParagraphStyle.name == "H1" || myLines[i].appliedParagraphStyle.name == "Equation 1" || myLines[i].appliedParagraphStyle.name == "Equation 2" || myLines[i].appliedParagraphStyle.name == "Equation 3")
                {
                    n=n+0; 
                     }
                 else
                 {
                    n=n+1;
                     
                     if (n%5==0)
                      {
                          
            
                          var myLineCount = myLines[i];
            
                            alert("myLineCount: " + myLineCount)
                  
                                 myText = myLib.assets.item("LN").placeAsset(myLines[i].insertionPoints[-2])[0];
                                        
                                    myText.appliedObjectStyle = app.activeDocument.objectStyles.item("LN_OBJ_STY");
            //~                                
            //~                          myText.insertionPoints[0].contents = "hi";
            
                        myText.insertionPoints[0].contents = Number(myLineCount);         //PLEASE HELP HERE
                        }
                  }
            }
            

             

             

            Thanks

            Beginner_X

            • 3. Re: Line count Help
              Jump_Over Level 5

              Hi,

               

              Did you test my solution?

              Is it returning any errors?

               

              Introducing var n is uneffective since code can scope by 5.

               

              You can't alert object but string, so:

               

              var myLineCount = i;

               

              Jarek

              • 4. Re: Line count Help
                BEGINNER_X Level 3

                Hi Jump_Over,

                 

                I tested your solution. But I got error and alert content also differ.

                 

                Even though you are always inspired lot of students like us.

                 

                I got output for this request.

                 

                Thanks for your valuable time effort.

                 

                Thanks

                Beginner_X