• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Find/Delete All Unused Empty Graphic Frames?

Community Beginner ,
Sep 26, 2018 Sep 26, 2018

Copy link to clipboard

Copied

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!

Views

5.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Sep 26, 2018 Sep 26, 2018

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

Votes

Translate

Translate
Guide ,
Sep 26, 2018 Sep 26, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 26, 2018 Sep 26, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 26, 2018 Sep 26, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 27, 2018 Sep 27, 2018

Copy link to clipboard

Copied

WONDERFUL!! Works perfect. Thank you so much!!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

Hello, thanks for script. I am trying this script, but it doesn't work. I am getting this error;Screen Shot 2019-11-27 at 00.04.58.png

Thank you for your help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 11, 2020 Feb 11, 2020

Copy link to clipboard

Copied

Same here. I get the "undefined is not an object" error as well.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 19, 2020 Apr 19, 2020

Copy link to clipboard

Copied

i'm getting undefined error also. anyone solve this?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2020 Apr 20, 2020

Copy link to clipboard

Copied

Try this (gets page items but not masterpage items that have not been overridden):

 

 

 

 

var api = app.activeDocument.allPageItems;
    
for (var i = 0; i < api.length; i++){
    var c = api[i].constructor.name
    if (c != "TextFrame") {
        var pi = api[i].allPageItems.length;
        if (api[i].fillColor.name == "None" && api[i].strokeColor.name == "None" && pi == 0) {
            api[i].remove();
        } 
    }else if (api[i].contents=="") {
        if (api[i].fillColor.name == "None" && api[i].strokeColor.name == "None") {
            api[i].remove();
        } 
    }
};   
  

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2020 Apr 20, 2020

Copy link to clipboard

Copied

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 )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2020 Apr 20, 2020

Copy link to clipboard

Copied

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 )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 24, 2022 Jan 24, 2022

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 03, 2022 Feb 03, 2022

Copy link to clipboard

Copied

LATEST

❤️

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines