Delete Empty (Anchor) frames
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Delete Empty (Anchor) frames
- This topic has 12 replies, 2 voices, and was last updated 7 years, 10 months ago by Masood Ahmad.
-
AuthorPosts
-
-
May 26, 2016 at 8:06 am #85233Masood AhmadParticipant
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
-
May 26, 2016 at 9:45 am #85236Masood AhmadParticipant
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.
-
May 26, 2016 at 9:54 am #85239Ari SingerMember
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(); } } }
-
May 26, 2016 at 10:06 am #85240Masood AhmadParticipant
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 == ""){
-
May 26, 2016 at 10:07 am #85241Ari SingerMember
Yes, I realized it just after I posted the script. It’s not fully baked yet…
-
May 26, 2016 at 10:18 am #85242Masood AhmadParticipant
I understand, good things take time.
-
May 27, 2016 at 3:00 am #85246Masood AhmadParticipant
Any chances to get it today…
-
May 29, 2016 at 5:15 pm #85282Ari SingerMember
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…
-
May 30, 2016 at 3:20 am #85289Masood AhmadParticipant
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
-
May 30, 2016 at 7:26 am #85291Ari SingerMember
Okay, now I understand. But what constitutes an ’empty’ graphic frame? When is considered to be empty?
-
May 30, 2016 at 7:34 am #85292Masood AhmadParticipant
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 :(
-
May 30, 2016 at 8:16 am #85294Masood AhmadParticipant
Any luck Ari…
-
May 31, 2016 at 4:00 am #85306Masood AhmadParticipant
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.
-
-
AuthorPosts
- You must be logged in to reply to this topic.