Delete Empty (Anchor) frames

Viewing 12 reply threads
  • Author
    Posts
    • #85233
      Masood Ahmad
      Participant

      Today, I came around a situation where I need to delete Empty Anchor (any)frames from the whole document. Can anyone please suggest some script for the same or edit the one by Harb:


      var myStories = app.activeDocument.stories.everyItem().getElements();
      for (i = myStories.length - 1; i >= 0; i--){
      var myTextFrames = myStories[i].textContainers;
      for (j = myTextFrames.length - 1; j >= 0; j--) {
      if (myTextFrames[j].contents == ""){
      myTextFrames[j].remove();
      }
      }
      }

      There was a topic where David explains “Finding Empty Text Frames in InDesign” https://creativepro.com/finding-empty-text-frames-in-indesign.php. He also talks about Harbs script called “DeleteEmptyFrames.jsx” https://creativepro.com/downloads/forcedl/DeleteEmptyFrames.jsx.

      Moreover, there is my article on the same “A Script for Cleaning Up Empty Text Frames” https://creativepro.com/script-cleaning-empty-text-frames.php

    • #85236
      Masood Ahmad
      Participant

      I figured out the problem, the anchored frame is in a Table.

      The script I shared in my article “A Script for Cleaning Up Empty Text Frames” https://creativepro.com/script-cleaning-empty-text-frames.php is working fine for the Anchored frame if it is not in a table.

      Can someone help me please on this.

    • #85239
      Ari Singer
      Member

      Try this out:

      //Ari S. - [email protected]
      // Delete empty anchored frames
      app.scriptPreferences.enableRedraw = false;
      app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Delete Empty Anchored Frames");
      function main(){
          var myDoc = app.activeDocument;
          app.findChangeGrepOptions.includeLockedLayersForFind = false;
          app.findChangeGrepOptions.includeLockedStoriesForFind = false;
          app.findChangeGrepOptions.includeHiddenLayers = false;
          app.findChangeGrepOptions.includeMasterPages = false;
          app.findChangeGrepOptions.includeFootnotes = true;
          app.findGrepPreferences = app.changeGrepPreferences = null;
          app.findGrepPreferences.findWhat = "~a";
          var myFound = myDoc.findGrep(true);
          for (i = (myFound.length - 1); i >= 0; i--){
              var myAnchorPosition = myFound[i];
              if (myAnchorPosition.texts[0].pageItems[0].contents == ""){
                  myAnchorPosition.texts[0].pageItems[0].remove();
                  }
              }
          }
      
    • #85240
      Masood Ahmad
      Participant

      Thanks Ari for writing a code for me.

      I tried this and got an error:
      Error Number: 55
      Error String: Object does not support the property or method ‘contents’

      The problem area:
      if (myAnchorPosition.texts[0].pageItems[0].contents == ""){

    • #85241
      Ari Singer
      Member

      Yes, I realized it just after I posted the script. It’s not fully baked yet…

    • #85242
      Masood Ahmad
      Participant

      I understand, good things take time.

    • #85246
      Masood Ahmad
      Participant

      Any chances to get it today…

    • #85282
      Ari Singer
      Member

      I tried using the code from Harbs that you provided, and it’s working fine by me even for frames that are anchored in tables. Maybe I misunderstood your question. Help me out…

    • #85289
      Masood Ahmad
      Participant

      Ari, The script is removing the empty Text frames only, where as there are empty graphic frames as well in my document. Therefore my requirement is to delete all the empty frames whether Text or Graphic and whether anchored or not within text or table.

      For your reference, the file is uploaded here: https://www.hightail.com/download/cUJVck8zQVMwMEZ1a3NUQw

      Thanks in advance

    • #85291
      Ari Singer
      Member

      Okay, now I understand. But what constitutes an ’empty’ graphic frame? When is considered to be empty?

    • #85292
      Masood Ahmad
      Participant

      Well, it came out from database, some data-merge. Now I want to get rid of all the empty frames to clean up my document.

      I’m trying but no luck so far :(

    • #85294
      Masood Ahmad
      Participant

      Any luck Ari…

    • #85306
      Masood Ahmad
      Participant

      Can anyone please create a script that can delete all kinds of empty frames from a document. These empty frames can be anywhere in the document, individual object, inline text and table etc.

      Except the one that has a Text-Wrap applied to it.

Viewing 12 reply threads
  • You must be logged in to reply to this topic.
>