4 Replies Latest reply on Mar 8, 2011 9:45 AM by Chang_indd

    How to select and alert

    Chang_indd Level 1

      Hi All,

       

      I want to delete text frame which has not contents. I do it manually but it takes time. Some of the text frames are within group of textframe.

       

      Can I select and alert my first instance of empty text frame in my document through js.

       

      Thank you,

       

      Chang

        • 1. Re: How to select and alert
          csm_phil Level 4

          Hi Chang,

           

          Here is my scripting code, i think you expect this:

           

          var myDoc = app.activeDocument;
          var myPageItems = myDoc.allPageItems;

          for (var i =0; i<myPageItems.length; i++){
              app.select(myPageItems[i]);
             
              alert(app.selection[0].constructor.name);
             
              if(app.selection[0].constructor.name == "TextFrame"){
                  if(app.selection[0].contents == ""){
                      try{
                          app.selection[0].locked=false;
                          app.selection[0].remove();
                          }catch(e){};
                      }
                  app.selection = null;
                  }
              }

           

          Thanks

          CSM_PHiL

          1 person found this helpful
          • 2. Re: How to select and alert
            Chang_indd Level 1

            Thanks for you reply.

             

            The provided code selects  and alert all the pageitems constructor name. And delete only ungrouped empty text frame.

             

            However, I want js code which only select and alert first instance of empty text frame within group or without group in my document.

             

            Anyone can help.

             

            Thanks,

            Chang

            • 3. Re: How to select and alert
              csm_phil Level 4

              Hi Chang,

               

               

              i have modified the js code as per your request.

               

               

              var myDoc = app.activeDocument;
              var myPageItems = myDoc.allPageItems;

               

              for (var i =0; i<myPageItems.length; i++){
                  app.select(myPageItems[i]);
                  var mySel = app.selection[0];
                  try{
                      mySel.locked=false;
                      }catch(e){};
                      if(mySel.constructor.name == "TextFrame"){
                          if(mySel.contents == ""){
                              try{

                                   //if you want alert enable the below line
                                  //alert(mySel.constructor.name);

                                  mySel.remove();
                                  }catch(e){};
                                  }
                              app.selection = null;
                              }
                          }

               

               

              Regards

              CSM_Phil

              • 4. Re: How to select and alert
                Chang_indd Level 1

                Dear CSM_Phil,

                 

                Thanks for quick reply, you have solved my problem.

                 

                I require this code.

                 

                Thanks again,

                Chang