3 Replies Latest reply on Mar 17, 2016 4:11 PM by @naomikennedy

    Deleting all hidden text frames unexpectedly deletes anchored (but visible) text frames. Why?

    @naomikennedy Level 1

      I'm trying to use the code below to delete all hidden text frames from a document. It's works pretty well BUT for some reason, deletes visible anchored text frames.

      (the currentTextFrame.length argument is to prevent it deleting hidden text frames if the content is threaded, in case the text then reflows into visible text frames. I'll need to work out a solution to that, but it's tomorrows problem.)

      I have a similar function for allGraphics and that does not delete anchored frames.

       

      Can someone point me in the right direction? I can add a check to see if the text frame is anchored, but I'm concerned I might miss the bigger problem.

       

      var myDocument = app.activeDocument;
      var myTextFrames = myDocument.stories.everyItem().textContainers.reverse();
      var myTextFramesLength = myTextFrames.length;
      for ( i = 0; i < myTextFramesLength; i++ ){
           var currentTextFrame = myTextFrames[i];
           if ((!currentTextFrame.visable) && (currentTextFrame.length ===1)){
                currentTextFrame[0].remove();
           }
      }
      
      

      _9781101983546_EPUB_SBs_indd___100_.png

       

      Edit: This is happening in CC 2014.0 and 2015.1, OSX 10.10

       

      Message was edited by: Naomi Kennedy

        • 2. Re: Deleting all hidden text frames unexpectedly deletes anchored (but visible) text frames. Why?
          Laubender Adobe Community Professional & MVP

          Hi Naomi,

          and there is an array of arrays with:

          myDocument.stories.everyItem().textContainers
          

           

          Test this:

          var a = app.documents[0].stories.everyItem().textContainers;
          for(var n=0;n<a.length;n++)
          {
              $.writeln(a[n].constructor.name);
          }
          

           

           

          I would suggest the following, that should work:

           

          var doc = app.documents[0];
          var myStoriesArray = doc.stories.everyItem().getElements();
          var storiesLength = myStoriesArray.length;
          
          var textContainersToRemoveIDs = [];
          
          
          for(var n=0;n<storiesLength;n++)
          {
              
              // A counter:
              var removeAllContainersOfStory = 0;
              for(var c=0;c<myStoriesArray[n].textContainers.length;c++)
              {
                  if(!myStoriesArray[n].textContainers[c].visible)
                  {
                      removeAllContainersOfStory++
                  };
                  
              }
              
              if(removeAllContainersOfStory == myStoriesArray[n].textContainers.length)
              for(var c=0;c<myStoriesArray[n].textContainers.length;c++)
              {
                  textContainersToRemoveIDs[textContainersToRemoveIDs.length++] = myStoriesArray[n].textContainers[c].id;
              }
              
          };
          
          // You can test the waters here:
          for(var n=0;n<textContainersToRemoveIDs.length;n++)
          {
              doc.pageItems.itemByID(textContainersToRemoveIDs[n]).remove();
          }
          

           

           

          Uwe

          • 3. Re: Deleting all hidden text frames unexpectedly deletes anchored (but visible) text frames. Why?
            @naomikennedy Level 1

            Looks like this combo of both replies works to solve the problem (visible typo AND currrentTextFrame[0] -- although I should probably update my variable name to currentStory for clarity).

             

            if ((!currentTextFrame[0].visible) && (currentTextFrame.length ===1)){
            

             

            However in practice, getting all the ids then deleting them could avoid many other potential problems, so I'll probably go ahead and update my code so it's structured like that.

             

            Thanks for your help!