13 Replies Latest reply on Apr 18, 2013 4:21 AM by BEGINNER_X

    Apply script on specific pages only

    MISESAJOUR

      Hi!

       

      I would like to know how to apply some script on specific pages only.

      I would like to apply it on pages number 4 to 50 on a 50 page project, and so exclude page 1, 2 and 3.

       

      Here is my actual script:

       

      var doc = app.activeDocument,
      objStyle = doc.objectStyles.itemByName('stylenamechosen'),
      a = doc.allGraphics,
      i = a.length;
      while( i-- ) a[i].parent.appliedObjectStyle = objStyle;

       

      Please let me know.

        • 1. Re: Apply script on specific pages only
          Jump_Over Level 5

          Hi,

           

          In case of your question you should modify the line:

          a = doc.allGraphics,

           

          with:

          a = doc.pages.itemByRange(3,-1).allGraphics,

           

          but basically:

          are you going to apply objectStyle to a graphics (images, pdfs, eps, etc) or to a frames which are their containers (rectangles, ovals, etc)?

           

          Jarek

          • 2. Re: Apply script on specific pages only
            Laubender Adobe Community Professional & MVP

            @Jarek – MISESAJOUR is applying object styles to the parent of a graphic.
            And that is the container.

             

            a = doc.allGraphics
            
            …
            
            a[i].parent.appliedObjectStyle = objStyle
            

             

             

            Uwe

            • 3. Re: Apply script on specific pages only
              Jump_Over Level 5

              @Uwe,

               

              Yea, right. I've overseen this... Thanks

               

              Jarek

              • 4. Re: Apply script on specific pages only
                BEGINNER_X Level 3

                Hi Laubender/Jump_Over/All,


                I try myself but I found Error in the Page range line code.


                Could anyone help me for my simple request.




                var myDoc = app.activeDocument;


                //~ var myGraphics = myDoc.allGraphics;


                var myGraphics = app.activeDocument.pages.itemByRange(3, -1).allGraphics;    //Error found in this line



                //~ alert(myGraphics.length)


                for(k=0; k<myGraphics.length; k++)

                {

                    myGraphics[k].parent.appliedObjectStyle = myDoc.objectStyles.item("testing");

                    }



                Thanks

                Beginner

                • 5. Re: Apply script on specific pages only
                  MISESAJOUR Level 1

                  Hi!

                   

                  Thanks all for your fast answers.

                   

                  I changed my code to:

                   

                  var doc = app.activeDocument,

                  objStyle = doc.objectStyles.itemByName('stylenamechosen'),

                  a = doc.pages.itemByRange(3,-1).allGraphics,

                  i = a.length;

                  while( i-- ) a[i].parent.appliedObjectStyle = objStyle;

                  But it doesn't work (on CS6) :-/

                  • 6. Re: Apply script on specific pages only
                    BEGINNER_X Level 3

                    Hi MISESAJOUR/All,

                     

                    For me and MISESAJOUR request, what i am thinking is:

                     

                     

                    1. Document having Graphics Property    //No Error

                     

                    var myGraphics = myDoc.allGraphics

                     

                    2. But Pages dont have Graphics Property. That why we are facing error.

                     

                    var myGraphics = app.activeDocument.pages.itemByRange(3, -1).allGraphics;    //Error found in this line

                     

                    Instead of using Graphics, we use rectangles or ovals then the script run properly.

                     

                     

                    Could anyone give solution for my above request.

                     

                    Please anyone run my above thread mentioned script.

                     

                    Thanks

                    Beginner

                    • 7. Re: Apply script on specific pages only
                      Jump_Over Level 5

                      @ BEGINNER_X

                      BEGINNER_X wrote:

                       

                      2. But Pages dont have Graphics Property...

                       

                      There is allGraphics property in use. It is valid for page.

                      Question is what kind of error is found in mentioned line on your side?

                       

                      Jarek

                      • 8. Re: Apply script on specific pages only
                        BEGINNER_X Level 3

                        Dear Jump_Over/All,

                         

                        Please help me for my coding why the error will come in when i am using the page range.

                         

                        var myDoc = app.activeDocument;

                        //~ var myGraphics = myDoc.allGraphics;

                        var myGraphics = app.activeDocument.pages.itemByRange(3, -1).allGraphics;    //Error found in this line

                          //~ alert(myGraphics.length)

                         

                        for(k=0; k<myGraphics.length; k++)

                        {

                            myGraphics[k].parent.appliedObjectStyle = myDoc.objectStyles.item("testing");

                            }

                         

                        Thanks

                        Beginner

                        • 9. Re: Apply script on specific pages only
                          Jump_Over Level 5

                          Hi,

                           

                          BEGINNER_X wrote:

                           

                          var myGraphics = app.activeDocument.pages.itemByRange(3, -1).allGraphics;    //Error found in this line

                           

                          I wish try to. But write the error content, pls.

                          How many pages has your doc?

                          • 10. Re: Apply script on specific pages only
                            BEGINNER_X Level 3

                            Dear Jump_Over,

                             

                            Sorry for the delay...

                             

                            //below code working fine

                            var myDoc = app.activeDocument;

                            var myGraphics = myDoc.allGraphics;

                            for(k=0; k<myGraphics.length; k++)

                            {

                                myGraphics[k].parent.appliedObjectStyle = myDoc.objectStyles.item("testing");

                                }

                             

                             

                            //below code not working with page range

                            var myDoc = app.activeDocument;

                            var myGraphics = app.activeDocument.pages.itemByRange(3, -1).allGraphics;    //Error found in this line

                            for(k=0; k<myGraphics.length; k++)

                            {

                                myGraphics[k].parent.appliedObjectStyle = myDoc.objectStyles.item("testing");

                                }

                             

                             

                            Screen Shot 2013-04-18 at 1.07.57 PM.png

                             

                            Document having 10 pages.

                             

                            Thanks

                            Beginner

                            • 11. Re: Apply script on specific pages only
                              [Jongware] Most Valuable Participant

                              That needed some trial-and-error and a bit of careful reasoning!

                               

                              Here is the deal. allGraphics is an [Array of Graphics]. So when you have a 'handle' on it, you can use .length, and iterate over its contents. No problem so far. However, the result of this line

                               

                              myGraphics = app.activeDocument.pages.itemByRange(3, -1).allGraphics;
                              

                               

                              is also an array! What you got is not a single array, but an array of arrays

                              So this works correctly:

                               

                              var doc = app.activeDocument;
                              var objStyle = doc.objectStyles.itemByName('Hi!');
                              var myGraphics = doc.pages.itemByRange(16, -1).allGraphics;    //Error found in this line
                              for(k=0; k<myGraphicsArray.length; k++)
                              {
                                for(l=0; l<myGraphicsArray[k].length; l++)
                                  myGraphicsArray[k][l].parent.appliedObjectStyle = objStyle;
                              }
                              
                              • 12. Re: Apply script on specific pages only
                                Jump_Over Level 5

                                Yeap,

                                 

                                Thats because myGraphics is an array of arrays. Each page created its own array of graphics.

                                So it should be modified:

                                 

                                var myDoc = app.activeDocument, currGraph;
                                var myGraphics = app.activeDocument.pages.itemByRange(3, -1).allGraphics; 
                                for(k=0; k<myGraphics.length; k++)
                                     for (i = 0; i < myGraphics[k].length; i++)
                                {
                                    currGraph = myGraphics[k][i];
                                    currGraph.parent.appliedObjectStyle = myDoc.objectStyles.item("testing");
                                    }
                                

                                 

                                my mistake:)

                                Jarek

                                 

                                Message was edited by: Jump_Over:  Ups. Too thoughtless and too slow :)

                                • 13. Re: Apply script on specific pages only
                                  BEGINNER_X Level 3

                                  Dear Jongware/Jump_Over/All,

                                   

                                  Thanks a lot for spending your valuables time for my question.

                                   

                                  Your people are inspired lot of beginners like me.

                                   

                                  I want to give correct answer for you. But that option is not Enable for me.

                                   

                                   

                                  Thanks

                                  Beginner