Copy link to clipboard
Copied
Hi,
Apologies if this seems obvious, I don't know much about javascript.
I'm trying to write a script to create a rectangle with no fill on my current page, and hyperlink the frame. I managed to create the frame, but I don't understand how to hyperlink it.
Here's the bit that works:
var myDocument = app.activeWindow.activePage
var myFrame = myDocument.rectangles.add();
myFrame.geometricBounds = ["297mm", "210mm", "274.75mm", "0mm"];
How do I add the URL https://www.adobe.com/ to this frame?
Thanks in advance.
Copy link to clipboard
Copied
Hi there,
See my answer to the following discussion, it has pieces of code that you can integrate into your script. Give it a shot
-Manan
Copy link to clipboard
Copied
Thank you for your reply.
I don't really understand how Javascript works, so I really couldn't figure out what to extract from your comment.
However, I got a friend to help and eventually came up with this which worked:
var myDocument = app.activeWindow.activePage;
var myFrame = myDocument.rectangles.add();
myFrame.geometricBounds = ["297mm", "210mm", "274.75mm", "0mm"];
var myURL = "https://www.adobe.com";
var source = app.documents[0].hyperlinkPageItemSources.add(myFrame);
var dest = app.documents[0].hyperlinkURLDestinations.add(myURL);
app.documents[0].hyperlinks.add(source, dest, {name:myURL});
Copy link to clipboard
Copied
Sorry to resurrect this thread - I thought it was working well, but I've realised that if a similar hyperlinked frame already exists on another master page, the code won't work: "This name is already in use by another object - Source: app.documents[0].hyperlinks.add(source, dest, {name:myURL});"
My understanding is that my code searches the entire document for a frame to add the hyperlink to, rather than the active page, but I don't know how to specify that. I tried "myDocument.hyperlinks.add(source, dest, {name:myURL});" but that doesn't work either. Sorry if it's really obvious!
Copy link to clipboard
Copied
Two hyperlinked frames can't have the same name. Setting "name:myURL" multiple times would cause this error. You can get around it by not setting the name, or by setting a custom name based on the frame's id, or a counter method, etc.
app.documents[0].hyperlinks.add(source, dest, {name:myURL + "_" source.id});
Copy link to clipboard
Copied
Thank you!
Your line of code was just missing a '+' before source.id it seems, now it works perfectly.