Skip to main content
mikefwd
Known Participant
November 9, 2018
Question

Delete empty graphics frames inside table

  • November 9, 2018
  • 1 reply
  • 1318 views

Hi all

I need a script to delete all empty graphics frames inside all tables of a multi page document.

The following script deletes text frames in the document but does not delete them if they are inside a table.

var myGraphicFrames = app.activeDocument.rectangles; 

for (i=myGraphicFrames.length-1; i>=0; i--) { 

    if (myGraphicFrames.graphics.length < 1) 

        myGraphicFrames.remove(); 

}

Anyone know how to rewrite this script so that it deletes graphic frames from within all tables as well?

I'm a total beginner at scripting so any help would be much appreciated.

Cheers

Mike

This topic has been closed for replies.

1 reply

Community Expert
November 9, 2018

Something like below should work, you need to iterate all the tables in the document and then each cell of all these tables

var myGraphicFrames = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().pageItems

for (i = 0; i < myGraphicFrames.length; i++)

{

    if (myGraphicFrames.graphics.length == 0)

        myGraphicFrames.remove();

}

-Manan

-Manan
Community Expert
November 9, 2018

I just noticed that the code i gave would not work on inner tables i.e. tables within a table cell and so forth. But that can be added to it, you just need to check each cell to check for tables within it and then the process repeats itself to iterate each cell. A recursive algorithm fits the bill in this case.

-Manan

-Manan
Peter Kahrel
Community Expert
Community Expert
November 9, 2018

In fact it's probably simpler to get a handle on all graphics, and delete those that are in a table:

g = app.documents[0].allGraphics;

for (i = g.length-1; i >= 0; i--) {

  if (g.parent.parent.parent instanceof Cell) {

    g.parent.remove();

  }

}

Peter