Copy link to clipboard
Copied
Does anybody know of a script I could run in InDesign to remove empty inline frames from multiple text frames throughout my document?
These frames are present for variable data, but once the data is merged I'd like to remove the unused frames to ensure what is left is centered in the text frame.
In my initial search, I found this script to delete empty text frames (DeleteEmptyFrames.jsx), but I don't know enough to modify this to find and delete the empty graphics frames WITHIN text frames (if that is even possible)
var myStories = app.activeDocument.stories.everyItem().getElements();
for (i = myStories.length - 1; i >= 0; i--){
var myTextFrames = myStories.textContainers;
for (j = myTextFrames.length - 1; j >= 0; j--) {
if (myTextFrames
.contents == ""){ myTextFrames
.remove(); }
}
}
Thank you to anyone willing to help!
Try this:
var myStories = app.activeDocument.stories.everyItem().getElements();
for (i = myStories.length - 1; i >= 0; i--){
var myPageItems = myStories.pageItems;
for (j = myPageItems.length - 1; j >= 0; j--) {
var ag = myPageItems
.allGraphics if (ag == ""){
myPageItems
.remove(); }
}
}
Copy link to clipboard
Copied
Try this:
var myStories = app.activeDocument.stories.everyItem().getElements();
for (i = myStories.length - 1; i >= 0; i--){
var myPageItems = myStories.pageItems;
for (j = myPageItems.length - 1; j >= 0; j--) {
var ag = myPageItems
.allGraphics if (ag == ""){
myPageItems
.remove(); }
}
}
Copy link to clipboard
Copied
Heck yes! That worked a treat
Thank you so much!
Copy link to clipboard
Copied
Hi,
There was a question in the script of the correct answer, so I modified it a little.
var myStories = app.activeDocument.stories.everyItem().getElements();
for (i = myStories.length - 1; i >= 0; i--){
var myPageItems = myStories[i].pageItems;
for (j = myPageItems.length - 1; j >= 0; j--) {
if (myPageItems[j].allGraphics.length == 0){
myPageItems[j].remove();
}
}
}
Copy link to clipboard
Copied
Hello, thanks for script. I am trying this script, but it doesn't work. I am getting this error;
Thank you for your help.
Copy link to clipboard
Copied
Has an update broken this script? I am also getting the "undefined is not an object" error when trying to run this script.
EDIT: ajabon's code posted above now works perfectly. Thanks ajabon!
Copy link to clipboard
Copied
Nicholas asked: Has an update broken this script?
Yes. This "update" was the introduction of the new forum software last year.
A lot of posted script code was damaged while moving threads over to the new forums.
Rely on the code thankfully posted by ajabon here:
FWIW: The code's issues are not the fault of the code poster.
It's just the fault of the ones who did the algorithm to move threads from the old Adobe forum software to the new Adobe forum software.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Thanks Uwe! That worked perfectly!