2 Replies Latest reply on Jul 20, 2012 5:00 AM by lbarth1212

    hyperlink name

    lbarth1212

      Hi,

       

      I am writing a script to convert url to hyperlinks because the included converter does not match url containing characters such as hyphen and the links are all named "Hyperlink ##" which is not easy to handle.

       

      So I write this function to convert the url I find with a grepFind :

       

      function url2hyperlink(url, textSource, urlLinkStyle) {

          // init hyperlink counter for this url

          if (typeof linksTable[url] == 'undefined') {linksTable[url] = 0;}

       

          // create name of hyperlink as url + hyperlink counter for this url to avoid duplicated names

          var hyperlinkName;

          if (linksTable[url] == 0) {hyperlinkName = url;}

          else {hyperlinkName = url + "_" + linksTable[url];}

       

          var linkDestination = myDocument.hyperlinkURLDestinations.add("http://" + url);

          var linkSource = myDocument.hyperlinkTextSources.add(textSource,{appliedCharacterStyle :urlLinkStyle});

          var myHyperLink = myDocument.hyperlinks.add(linkSource, linkDestination,{name:hyperlinkName});

       

          // increment hyperlink counter for this url

          linksTable[url]++;

      } // end url2hyperlink

       

      But I have an error "This name is already used by another object". I do not know wich object.

       

      If I change :

          var myHyperLink = myDocument.hyperlinks.add(linkSource, linkDestination,{name:hyperlinkName});

      to

          var myHyperLink = myDocument.hyperlinks.add(linkSource, linkDestination,{name:"anytext" + hyperlinkName});

       

      I do not have the error.

      The string can really be "anytext" I tried "http://" or "\u2799" it works (an empty string "" does not work).

       

      Does somebody knows what is happening in this script ?

       

      Regards,

      Lionel