5 Replies Latest reply on Nov 9, 2011 3:44 AM by csm_phil

    An object's Page number on CS4

    seba1395

      Hello,

      I would like to do my script only on even page.

      In CS5, all is ok :

       

       

      var myStories = app.activeDocument.allPageItems;

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

              if(myStories[i]  instanceof TextFrame){

                      if(myStories[i].name=="Post_it" || myStories[i].label=="Post_it"){

                              var num_page_active = myStories[i].parentPage.name;

                               Number.prototype.isEven = function (){return (this%2 == 0) ? true : false;}

                              if(Number(num_page_active).isEven()==false){

                                  var g_obj1 = get1(myStories[i]);

                                  var g_obj2 = get2(myStories[i]);

                                  var g_obj3 = get3(myStories[i]);

                                  var g_obj4 = get4(myStories[i]) + 5 ;

                                  myStories[i].geometricBounds = [g_obj1,g_obj2,g_obj3,g_obj4];

                                  myStories[i].name="Post_it_Dec";

                                  myStories[i].label="Post_it_Dec";

                              }

                        }

              }

      }

       

       

      But in CS4, the parent.name give me some problème that I can't resolved.

      In CS4, it does'nt know ".name" but ".label" only.

       

      So this does'nt work for CS4 :

       

      var myStories = app.activeDocument.allPageItems;

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

       

       

                                    if( myStories[i].label=="Post_it"){

                                              myStories[i].select();

                                              var num_page_active = myStories[i].parent.name;

                                              Number.prototype.isEven = function (){return (this%2 == 0) ? true : false;}

                                              if(Number(num_page_active).isEven()==false){

                                                                            var g_obj1 = get1(myStories[i]);

                                                                            var g_obj2 = get2(myStories[i]);

                                                                            var g_obj3 = get3(myStories[i]);

                                                                            var g_obj4 = get4(myStories[i]) + 5 ;

                                                                            myStories[i].geometricBounds = [g_obj1,g_obj2,g_obj3,g_obj4];

                                                                            myStories[i].label ="Post_it_Dec";

                                              }

                }

      }


       

      Can you help me?

       

        • 1. Re: An object's Page number on CS4
          csm_phil Level 4

          Hi seba,

           

          please try this.

           

           

          var num_page_active = myStories[i].parent.characters[0].parentTextFrames[0].parent.name;
          

           

           

          thx

          csm_phil

          • 2. Re: An object's Page number on CS4
            seba1395 Level 1

            Hello, doesn't work...

            indd1.jpg

            • 3. Re: An object's Page number on CS4
              csm_phil Level 4

              Hi seba,

               

              Please try the below js code and rever back for updates if any.

               

               

              var myDoc = app.activeDocument;
              myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.picas;
              myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.picas; 
              
              var myStories = app.activeDocument.allPageItems;
              
              for(var i=0;i<myStories.length;i++){
              
                      if(myStories[i]  instanceof TextFrame){
              
                              if(myStories[i].label=="Post_it"){
              
                                      //var num_page_active = myStories[i].parent;
                                      var num_page_active = myStories[i].parent.characters[0].parentTextFrames[0].parent.name;
                                      alert(num_page_active);
              
                                       Number.prototype.isEven = function (){return (this%2 == 0) ? true : false;}
              
                                      if(Number(num_page_active).isEven()==false){
              
                                          var g_obj1 = (myStories[i].parent.characters[0].parentTextFrames[0].geometricBounds[0]);
              
                                          var g_obj2 = (myStories[i].parent.characters[0].parentTextFrames[0].geometricBounds[1]);
              
                                          var g_obj3 = (myStories[i].parent.characters[0].parentTextFrames[0].geometricBounds[2]);
              
                                          var g_obj4 = (myStories[i].parent.characters[0].parentTextFrames[0].geometricBounds[3]) + 18;
              
                                          myStories[i].parent.characters[0].parentTextFrames[0].geometricBounds = [g_obj1,g_obj2,g_obj3,g_obj4];
              
              //                            myStories[i].name="Post_it_Dec";
              
                                          myStories[i].label="Post_it_Dec";
              
                                      }
              
                                }
              
                      }
              
              }
              

               

               

              thx

              csm_phil

              • 4. Re: An object's Page number on CS4
                seba1395 Level 1

                Hi, It's the same problem, It doesn't like this : var num_page_active = myStories[i].parent.characters[0].parentTextFrames[0].parent.name;

                 

                Thank a lot for your help! It's very difficult to get number's page of this element.

                • 5. Re: An object's Page number on CS4
                  csm_phil Level 4

                  Hi Seba,

                   

                  I get the pag number from the anchored textframes of the corresponding page, Otherwise can you post the snapshot will be clear to us.

                  the above code will alert the page number from the corresponding page of the anchored position link.

                   

                  thx

                  csm_phil.