4 Replies Latest reply on Dec 2, 2009 3:30 AM by JulienFR

    erase blank text Frames in document

    JulienFR

      I have many blank text frames in my documents. i want to erase them with a script.

       

      I try this script but there return an error sometimes "undefine"... "not an object"

       

      this : (IT'S WRONG CODE DO NOT COPY).

      {
         app.findGrepPreferences = app.changeGrepPreferences = null;

       

         app.findGrepPreferences.findWhat = '\\A\\Z';

       

         var blocsvides = app.activeDocument.findGrep (true);

       

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

       

            blocsvides[i].parentTextFrames[0].remove()                   // <---- in this line there are an error

       

         }

       

      there're many frames in my documents, image, text and undefined objet with color too.

       

      Thanks to help me. :-)

      Julien.

        • 1. Re: erase blank text Frames in document
          Harbs. Level 6

          Try something like this:

           

          var stories = app.documents[0].stories.everyItem().getElements();
          for(var i=0;i<stories.length;i++){
            if(stories[i].contents==""){
              var containers = stories[i].textContainers;
              while (c=containers.pop()){
                c.remove();
              }
            }
          }
          
          

           

          Harbs

          1 person found this helpful
          • 2. Re: erase blank text Frames in document
            JulienFR Level 1

            yes. thanks Harbs. you're very rapid.

            it's perfect if you don't have color back frame.

            I have many text frames with nothing or just color back. It's strange because when i slide from Illustrator window an object directly in my InD documents (or Copy/paste), they becomes Text object or image object. So with your script it's erase all :-))).

            I think to try create an popup to choose if you want color back or simply all text frame.

            what do u think about this idea? extended to image bloc?

            finally it miss an "identical selection"as in Illustrator.

             

             

            Thanks.

            • 3. Re: erase blank text Frames in document
              Harbs. Level 6

              This should leave any visible frames:

               

              var noColor = app.documents[0].swatches.item(0);
              var stories = app.documents[0].stories.everyItem().getElements();
              for(var i=0;i<stories.length;i++){
                if(stories[i].contents==""){
                  var containers = stories[i].textContainers;
                  while (c=containers.pop()){
                      if(c.fillColor != noColor){continue}
                      if(c.strokeColor != noColor && c.strokeWeight > 0){continue}
                    c.remove();
                  }
                }
              }
              
              
              • 4. Re: erase blank text Frames in document
                JulienFR Level 1

                it's perfect!

                nice job !

                Thank you.

                (i understand nothing of your code... i gonna learn C and C++ . after i'll learn javascript. )