5 Replies Latest reply on Nov 25, 2015 12:47 PM by Per Berntsen

    Script to delete all images, text frames and page numbers on a layer

    Per Berntsen Adobe Community Professional

      I have a 364 page book with 322 illustrations, mainly photographs, for offset printing.

      The photographs will be overprinted with varnish on a fifth plate, and I set this up as follows:

      On a new layer, (duplicate of Layer 1) all the photos are deleted, but not their frames.

      The frames are then filled with 100% black.

      All text frames and page numbers will also have to be deleted.

       

      I realise I could have made this job easier if I had placed all images on their own layer to begin with, but unfortunately I didn't.

      And I don't do scripting myself, so I was wondering if someone has a script that will do this ...

      Using CC 2015.1 on Windows 7.

        • 1. Re: Script to delete all images, text frames and page numbers on a layer
          LeoMari Level 2

          Today I did not have time to finish, which gave time to do so far is this:

           

            var myDocuments = app.documents.everyItem();
              var myLayers = myDocuments.layers.everyItem();
              var myStories = app.activeDocument.stories.everyItem().getElements(); 
              var myDoc = app.activeDocument;
              var myLayer = "palette"; //Add your layer name here
              var NewLayer = myDoc.layers.item(myLayer).duplicate();
              myDocuments.pageItems.everyItem().locked = false;
              myLayers.locked = false;
              myDoc.layers.item(myLayer).visible = false;
              NewLayer.name = "SampleNew";    //Add your new layer name here
          
          
                          re();
                          function re(){
                              var link, image;
                              var openDocs = app.documents;
                              var openDocsLen = openDocs.length;
                              for (var d = 0; d < openDocsLen; d ++){
                              currDoc = openDocs[d],
                              links = currDoc.links,
                              counter = 0;
                              myLayer.locked = true;
                              myDocuments.layers.item(myLayer).locked = true;
                                  for (var i = links.length-1; i >= 0; i--) {
                                      if (links[i].hasOwnProperty('relink')) {
                                          try {
                                              link = links[i];
                                              image = link.parent;
                                              image.remove();
                                              counter++;
                                          }
                                          catch (err) {
                                              $.writeln(i + " - " + err);
                                          }
                                      }
                                  }
                              }
                            }
          
          
                  var myStories = app.activeDocument.stories.everyItem().getElements(); 
                  for (i = myStories.length - 1; i >= 0; i--){ 
                      var myTextFrames = myStories[i].textContainers; 
                      for (j = myTextFrames.length - 1; j >= 0; j--){ 
                      myTextFrames[j].remove(); 
                      } 
                  } 
          

           

          If no one finished the second finalized.

           

          Hug!

          • 2. Re: Script to delete all images, text frames and page numbers on a layer
            Per Berntsen Adobe Community Professional

            Thank you!

            This seems to work, except that it does not fill the image frames with 100% black.

            Is that possible to implement?

            • 3. Re: Script to delete all images, text frames and page numbers on a layer
              Per Berntsen Adobe Community Professional

              The script has been a great help. Filling the frames manually wasn't too much work.

              Thanks again!

              • 4. Re: Script to delete all images, text frames and page numbers on a layer
                LeoMari Level 2

                I'm glad to be helpful ..

                Try this:

                #target indesign
                
                    var myDocuments = app.documents.everyItem();
                    var myLayers = myDocuments.layers.everyItem();
                    var myStories = app.activeDocument.stories.everyItem().getElements(); 
                    var myDoc = app.activeDocument;
                    var myLayer = "palette"; //Add your layer name here
                    var NewLayer = myDoc.layers.item(myLayer).duplicate();
                    myDocuments.pageItems.everyItem().locked = false;
                    myLayers.locked = false;
                    myDoc.layers.item(myLayer).visible = false;
                    NewLayer.name = "SampleNew";    //Add your new layer name here
                
                                re();
                                function re(){
                                    var link, image;
                                    var openDocs = app.documents;
                                    var openDocsLen = openDocs.length;
                                    for (var d = 0; d < openDocsLen; d ++){
                                    currDoc = openDocs[d],
                                    links = currDoc.links,
                                    counter = 0;
                                    myLayer.locked = true;
                                    myDocuments.layers.item(myLayer).locked = true;
                                        for (var i = links.length-1; i >= 0; i--) {
                                            if (links[i].hasOwnProperty('relink')) {
                                                try {
                                                    link = links[i];
                                                    image = link.parent;
                                                    image.remove();
                                                    counter++;
                                                }
                                                catch (err) {
                                                    $.writeln(i + " - " + err);
                                                }
                                            }
                                        }
                                    }
                                  }
                
                                    app.findObjectPreferences = app.changeObjectPreferences = null;
                                    app.findObjectPreferences.fillColor = "None";
                                    app.changeObjectPreferences.fillColor = "Black";
                                    app.changeObject();
                
                        var myStories = app.activeDocument.stories.everyItem().getElements(); 
                        for (i = myStories.length - 1; i >= 0; i--){ 
                            var myTextFrames = myStories[i].textContainers; 
                            for (j = myTextFrames.length - 1; j >= 0; j--){ 
                            myTextFrames[j].remove(); 
                            } 
                        } 
                

                 

                Hug.

                Leonardo

                • 5. Re: Script to delete all images, text frames and page numbers on a layer
                  Per Berntsen Adobe Community Professional

                  This worked perfectly. Thanks again!