7 Replies Latest reply on Apr 21, 2011 8:47 AM by NixW44

    Modifying Script to delete Graphics in a Table




      I used this script from an earlier discussion in this forum (by Kasyan Servetsky) to delete every instance of a graphic when I select it and run the javascript.



      if (app.documents.length == 0) ErrorExit("No documents are open. Please open a document and try again.", true);

      var doc = app.activeDocument;

      var links = doc.links;

      if (app.selection.length != 1) ErrorExit("Select a graphic frame with graphic.", true);

      var sel = app.selection[0];

      if (sel.graphics.length != 1) ErrorExit("Selected graphic frame should contain an graphic.", true);

      var selectedLink = sel.graphics[0].itemLink;

      var selectedLinkPath = selectedLink.filePath + "";

      if (selectedLink == null) ErrorExit("Selected item doesn't contain a link.", true);

      var allInstances = [];

      var counter = 0;


      for (var j = 0; j < links.length; j++) {

           if (links[j].filePath == selectedLink.filePath) {





      if (allInstances.length == 1) {

           if (!confirm("This link has only one instance. Do you want to delete it?", false, "Delete all instances of a link")) exit();



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

           try {

                var link = allInstances[i];

                var graphic = link.parent;

                var frame = graphic.parent;




           catch(err) {

                $.writeln(i + " - " + err);




      if (counter == 0) {

           alert("No links have been removed", "Delete all instances of a link");


      else if (counter == 1) {

           alert("One clink has been removed", "Delete all instances of a link");


      else if (counter > 1) {

           alert(counter  + " links have been removed", "Delete all instances of a link");



      function ErrorExit(myMessage, myIcon) {

           alert(myMessage, "Error", myIcon);





      It works great, but it wont delete the instances of a graphic that are in a table unless the table is split into two columns. Is there anyway to modify this javascript, so it will delete all instances of the current selected image even if it's in a table that's set inline inside of a text frame?