Skip to main content
Participant
Sep 26, 2018 3:47 PM UTC
Answered

Find/Delete All Unused Empty Graphic Frames?

I've seen some scripts for deleting unused text frames and tried haphazardly to modify it to find and delete empty graphic frames instead with no success. Does anyone have any idea how this might be possible? I have very little knowledge in scripts, thank you in advance for your help!  Also, apologies if this is posted in the wrong place!

FRIdNGE
FRIdNGECorrect answer
Sep 26, 2018 10:51 PM UTC

Hi,

// by FRIdNGE [September 2018]

var myDoc = app.activeDocument,

myRectangles = myDoc.rectangles.everyItem().getElements(),

myOvals = myDoc.ovals.everyItem().getElements(),

myPolygons = myDoc.polygons.everyItem().getElements(),

myGraphicFrames = myRectangles.concat(myOvals.concat(myPolygons)),

G = myGraphicFrames.length;

while ( G-- ) if ( myGraphicFrames.graphics.length == 0 ) myGraphicFrames.remove();

Best,

Michel, for FRIdNGE

13 replies

ChrisPBeets
Participant
Jan 25, 2022 6:43 AM UTC

I was thrilled to find the solution that worked for me at https://www.eehelp.com/question/indesign-remove-all-the-empty-frames-online-script/   as an answer to this: I need to delete all images empty inline in a document. These empty frames inline appear once a data merge is done.

var doc = app.documents[0]
var inlines = doc.stories.everyItem().pageItems.everyItem().getElements();
while(fr=inlines.pop()){
  if(fr instanceof Group){continue}
  if(fr instanceof TextFrame){
    if(fr.contents == ""){fr.remove()}
    continue;
  }
  if(fr.graphics.length==0){fr.remove()}
}

 

Translate
Zachary0526
Inspiring
Feb 3, 2022 3:08 PM UTC

❤️

Translate
Community Expert
Apr 20, 2020 6:20 PM UTC

Hi Lindsay,

the main question is: How would you define an empty graphic frame?

My answer would be: That's a frame without a purpose.

 

If you agree to that, then the frame could be identified like that:

1. A frame with no fill color.

2. A frame with no stroke applied.

3. A frame where no transparency effect is applied.

 

4. I think we could agree, that an empty graphic frame must not contain any other object.

Be it an image or a graphic or some other stuff that was pasted inside.

But: Is a frame without a purpose, if it contains other frames without a purpose?

( Then run a possible script that removes "empty frames" several times on the same document. )

 

Hm. But how about empty anchored frames?

Sometimes they fulfill a purpose like parting text from other text if they are anchored inline or above line.

Should we include or exclude them?

 

And finally:

How about text wrap?

Would you like to remove an empty graphic frame that has text wrap applied?

 

Regards,
Uwe Laubender

( ACP )

Translate
Community Expert
Apr 20, 2020 3:57 PM UTC

Hi together,

I think some of the original code of Michel has changed while this thread was moved to this new Adobe InDesign Forum last year. Hope, that Michel will come back soon to edit his posts.

 

Regards,
Uwe Laubender

( ACP )

Translate
FRIdNGE
FRIdNGECorrect answer
Sep 26, 2018 10:51 PM UTC

Hi,

// by FRIdNGE [September 2018]

var myDoc = app.activeDocument,

myRectangles = myDoc.rectangles.everyItem().getElements(),

myOvals = myDoc.ovals.everyItem().getElements(),

myPolygons = myDoc.polygons.everyItem().getElements(),

myGraphicFrames = myRectangles.concat(myOvals.concat(myPolygons)),

G = myGraphicFrames.length;

while ( G-- ) if ( myGraphicFrames.graphics.length == 0 ) myGraphicFrames.remove();

Best,

Michel, for FRIdNGE

Translate
Participant
Sep 26, 2018 11:33 PM UTC

Thanks so much! It works like a charm, my only issue is that it works TOO much. It's deleting all my empty unused frames super swiftly which is great but it's also deleting boxes and circles that are filled with color. For instance I have some colored page tabs (rectangles) that are deleted as well. Is there any way to set up a parameter about not deleting color-filled frames? It's not a huge deal but I wanted to ask. I've found a slight work around by making these objects assigned as "Text" instead of "Graphic" which again, isn't a big issue. For some reason it also deletes the frames if they are left "Unassigned". Anyway, thanks for the help, this will work wonders for me.

Translate
FRIdNGE
Sep 27, 2018 12:09 AM UTC

Replace the last line by this one! …

while ( G-- ) if ( myGraphicFrames.graphics.length == 0 && myGraphicFrames.contentType == ContentType.GRAPHIC_TYPE && myGraphicFrames.fillColor.name == "None") myGraphicFrames.remove();

Best,

Michel

Translate