1 Reply Latest reply on Aug 18, 2013 9:41 PM by Sajeev Sridharan

    function to check if a link is used many times

    bastieneichenberger Level 1

      Hi,

       

      I try to create a script to resize all links in a document. For this script I need a function to know if the same image is used many times.

      Has someone an ideas how to do this? I didn't find a function for that.

       

      My ideas would look like this:

       

       

      function is_link_used_many_time(link_item){
          // get all links
          var array_all_links = doc_package.links;
          // delete the link_item from the array
          // code
      
          //check if the array contains a link with the same name
          for(var i = 0; i<array_all_links.length; i++){
              var current_link = array_all_links[i];
              if(link_item.name == current_link.name){
                  alert("links used many time"+current_link.name);
                  // create a collection with all links
              }
          }
      }
      
      

       

       

      Thanks you!

        • 1. Re: function to check if a link is used many times
          Sajeev Sridharan Level 4

          Try this,

           

          var doc = app.activeDocument;

          var links = doc.links;

          var count=0;

           

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

          {

              var image = links[i].name;

              for(c=0;c<links.length;c++)

              {

                  if(links[i].name == links[c].name)

                  {

                      count++;

                      if(count>1)

                      {

                          var imagePage = doc.links[i].parent.parentPage.name;

                          alert("Image name: "+ links[i].name + "\rPage Number: " + imagePage + "\r" + count + " times used");

                      }

                  }

              }

              count=0;

          }

           

           

          Vandy