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
You probably try to create a link with a name that already exists, which can happen if a URL occurs more than once in a document. Try adding a suffix such as "_1" to the name. Or safer: continue to add a suffix until you find a unique name. You could end up with "name_1", "name_2", "name_3", etc.
Peter
North America
Europe, Middle East and Africa
Asia Pacific