Copy link to clipboard
Copied
I know this has come up multiple times. I have read through all the threads, and tried many of the scripts that people have written code for. Some work partially, some Give me error 21 and cant finish - so maybe they work, But i cannot seem to find a script that will delete Empty frames after a data merge, that also Deletes Frames which are EMPTY BUT have a Paragraph Symbol & Figure Space left.
I have tried a Script that David Blatner posted in 2018 on Creative Pro,
I have tried a script UWE posted back in 2013 that has some updates listed to it. I have tried 4 others labeled "RemoveEmptyFrame", "EmptyFrameRemover", "DeleteEmptyFrames", and "by_LFC Remove Empty Frame". I have found a post on a website which links to a script but it gives me a 404 error, so i have not tried that one. I also found one posted on "Colecandoo" for a "updated-empty-frame-remover-1-1" but his link is broken as it takes you to the Adobe community forum homepage instaed of to the thread that was written (The website blogger is also a contributer on creativepro)
I most recently tried this code, but i get an error on Line 19: Would anyone be able to help on a solution for me? i havent seen any updates on this specific request since 2019.
var myDocument = app.activeDocument;
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.findWhat = "<FEFF>";
app.changeTextPreferences.changeTo = "";
myDocument.changeText();
app.findTextPreferences = app.changeTextPreferences = null;
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--) {
var stroke = myTextFrames.strokeWeight;
var color = myTextFrames.fillColor.name;
var wrap = myTextFrames.textWrapPreferences.textWrapMode;
//alert (color)
if (myTextFrames.contents == "" && stroke == "0" && color == "None" && wrap === TextWrapModes.NONE){
//alert ("yes")
myTextFrames.remove();
}
}
}
var _d = app.documents[0],
_allStories = _d.stories;
for (var n = _allStories.length - 1; n >= 0; n--){
var _storyAllTextFrames = _allStories.textContainers;
for (var m = _storyAllTextFrames.length - 1; m >= 0; m--){
if (_storyAllTextFrames.contents === "")
try{
_storyAllTextFrames.contentType = ContentType.UNASSIGNED;
}catch(e){};
}
}
var myGraphicFrames = app.activeDocument.rectangles;
for (i=myGraphicFrames.length-1; i>=0; i--) {
var stroke = myGraphicFrames.strokeWeight;
var color = myGraphicFrames.fillColor.name;
var wrap = myGraphicFrames.textWrapPreferences.textWrapMode;
if (myGraphicFrames.graphics.length < 1 && stroke == "0" && color == "None" && wrap === TextWrapModes.NONE)
myGraphicFrames.remove();
}
var myOvalFrames = app.activeDocument.ovals;
for (i=myOvalFrames.length-1; i>=0; i--) {
var stroke = myOvalFrames.strokeWeight;
var color = myOvalFrames.fillColor.name;
var wrap = myOvalFrames.textWrapPreferences.textWrapMode;
if (myOvalFrames.graphics.length < 1 && stroke == "0" && color == "None" && wrap === TextWrapModes.NONE)
myOvalFrames.remove();
}
var myPolygonFrames = app.activeDocument.polygons;
for (i=myPolygonFrames.length-1; i>=0; i--) {
var stroke = myPolygonFrames.strokeWeight;
var color = myPolygonFrames.fillColor.name;
var wrap = myPolygonFrames.textWrapPreferences.textWrapMode;
if (myPolygonFrames.graphics.length < 1 && stroke == "0" && color == "None" && wrap === TextWrapModes.NONE)
myPolygonFrames.remove();
}
That makes things clearer. Try this:
frames = app.activeDocument.allPageItems;
for (i = frames.length-1; i >= 0; i--) {
if (frames[i] instanceof TextFrame && frames[i].parentStory.contents.length <= 3) {
frames[i].remove();
}
}
By the way, there's no need for a hard return to show the paragraph's shading. Any character will do: discretionary line break (same as zero-width space), end-nested-style, and various others. They are much less intrusive than return characters.
Copy link to clipboard
Copied
Was hoping someone would be able to help out on this.
Copy link to clipboard
Copied
Maybe it's as straightforward as this:
frames = app.activeDocument.textFrames.everyItem().getElements();
for (i = frames.length-1; i >= 0; i--) {
if (frames[i].contents == '' || frames[i].contents == '\r\u2007') {
frames[i].remove();
}
}
If this doesn't work, maybe post a sample document.
P.
Copy link to clipboard
Copied
The Legend himself answered my question!!! i will try this in a few minutes. Thanks for the help and replying.
Copy link to clipboard
Copied
It did not delete Empty frames that have a Paragraph return and a Figure space.
I am trying to get something to delete the Blue bar in the front of the red, and on other pages deleteing the red in front of the blue. I used to have just the paragraph symbol, and the previous scrip worked fine but for issues relating to alignment i had to add a return at the end of the Data merge placeholder text so the text below would be in the same place. regardless, and now none of the "empty Frames" scripts will delete the Bar. The bar heading is also paragraph shading so its not a graphic frame with a fill. I can export a completed Data Merge Page and link it if needed.
Copy link to clipboard
Copied
Could you attach that file (or part of it)? 'Empty' can mean various things in InDesign.
Copy link to clipboard
Copied
I will shortly i have been running a script (which is still "Checking") for 2 hours now... i can see the script works on the item i am trying to delete as the first page the item has been removed, but indesign is still "locked" up. I will post the file in a few minutes.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Could you indicate which frames should be removed? There are lots of empty rectangles. Then there are frames with a red fill that sometimes sit on top of blue frames with the text 'cost 00'.
And there are no figure spaces in the dicument, by the way.. Maybe you confused the end-of-story # character with the figure space, which too is # but sits a bit lower and has a dot in it.
Copy link to clipboard
Copied
You are right it should have been end of story character. The empty rectangles are there if something gets an explosion on the corner. Empty frames with a red fill should be deleted leaving only the blue and empty frames with a blue fills over red should be deleted.. To be clear they are not empty frames with a color fill. they are a frame with a paragraph shading. That is becuase i had to add a paragraph return to my data merge setup so the <<text1.1>> displays correctly spaced beneath.
The final should look like some variation of this:
Copy link to clipboard
Copied
That makes things clearer. Try this:
frames = app.activeDocument.allPageItems;
for (i = frames.length-1; i >= 0; i--) {
if (frames[i] instanceof TextFrame && frames[i].parentStory.contents.length <= 3) {
frames[i].remove();
}
}
By the way, there's no need for a hard return to show the paragraph's shading. Any character will do: discretionary line break (same as zero-width space), end-nested-style, and various others. They are much less intrusive than return characters.
Copy link to clipboard
Copied
I will try this. the hard return is so the spacing of the description text is always spaced properly below the bar especially if the data merge is two long and makes the bar two lines. I tried everything (text wrap options, text frame options, etc) this is the only one that seemed to work properly no matter how many lines the bar grew.
Copy link to clipboard
Copied
Wow that worked beautifully, it still left the empty boxes in the corner but i have another script that works that i ran right after. Thanks for your thorough help Peter.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now