Skip to main content
Known Participant
August 28, 2023
Answered

Find and Remove Empty Frames after Data Merge

  • August 28, 2023
  • 3 replies
  • 1094 views

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();

}

 

This topic has been closed for replies.
Correct answer Peter Kahrel

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.

3 replies

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
August 30, 2023

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.

Known Participant
August 30, 2023

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.

Peter Kahrel
Community Expert
Community Expert
August 29, 2023

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.

 

Known Participant
August 29, 2023

The Legend himself answered my question!!!  i will try this in a few minutes. Thanks for the help and replying.

Known Participant
August 29, 2023

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.

Known Participant
August 29, 2023

Was hoping someone would be able to help out on this.