4 Replies Latest reply on Jul 14, 2015 10:55 AM by Laubender

    How to remove all image in open docs

    Johnwhite Level 1

      Hi, experts

       

      How to make this script work in remove all image in open docs?

       

         function re(){

               var link, image, frame;
               var openDocs = app.documents;
               var openDocsLen = openDocs.length;
               for (var d = 0; d < openDocsLen; d ++){
               currDoc = openDocs[d], 
               links = currDoc.links, 
               counter = 0; 
                   for (var i = links.length-1; i >= 0; i--) { 
                       if (links[i] == docs.links) { 
                           try { 
                               link = links[i]; 
                               image = link.parent; 
                               frame = image.parent; 
                               frame.remove(); 
                               counter++; 
                           } 
                           catch (err) { 
                               $.writeln(i + " - " + err); 
                           } 
                       } 
                   }
               }
                }      

       

      regard

      John

        • 1. Re: How to remove all image in open docs
          Laubender Adobe Community Professional & MVP

          Hi John,

          as I can see you want to remove all graphics with their containers using the links.

          I would rather go with the allGraphics array of a document, because there could be links, that are not graphic related and there could be graphics embedded without links.

           

          var myDoc = app.documents[0];
          var myAllGraphicsArray = myDoc.allGraphics;
          
          for(var n=myAllGraphicsArray.length-1;n>=0;n--){
             
              //Graphics plus containers:
              myAllGraphicsArray[n].parent.remove();
             
              //Graphics only:
              //myAllGraphicsArray[n].remove();
             
              };
          

           

          Uwe

          • 2. Re: How to remove all image in open docs
            Vel Prakash Level 1

            Dear John,

             

            Try your updated code.

             

             

            re();

            function re(){

                 var link, image, frame;

                 var openDocs = app.documents;

                 var openDocsLen = openDocs.length;

                 for (var d = 0; d < openDocsLen; d ++){

                 currDoc = openDocs[d], 

                 links = currDoc.links, 

                 counter = 0; 

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

                         if (links[i].hasOwnProperty('relink')) { 

                             try { 

                                 link = links[i]; 

                                 image = link.parent; 

                                 frame = image.parent; 

                                 frame.remove(); 

                                 counter++; 

                             } 

                             catch (err) { 

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

                             } 

                         } 

                     }

                 }

              }

             

            Warm Regards,

            K.Velprakash.

            • 3. Re: How to remove all image in open docs
              Johnwhite Level 1

              thank guys, thank so much.

              both very useful for me, but            Community Member

               

               

              • 4. Re: How to remove all image in open docs
                Laubender Adobe Community Professional & MVP

                Hi John,

                mine is also working on all open documents. You just have to wrap it with another for loop like that:

                 

                var myOpenDocs = app.documents.everyItem().getElements();
                
                for(var d=0;d<myOpenDocs.length;d++){
                
                    var myAllGraphicsArray = myOpenDocs[d].allGraphics;
                   
                    for(var n=myAllGraphicsArray.length-1;n>=0;n--){
                       
                        //Graphics plus containers:
                        myAllGraphicsArray[n].parent.remove();
                       
                        //Graphics only:
                        //myAllGraphicsArray[n].remove();
                       
                        };
                
                    };
                

                 

                Uwe