Hyperlink External Page Destinations get duplicated, how can I avoid this?

I’ve been creating a hyperlinked document, and I’m generating links to internal and external page destinations, using HyperlinkPageDestination (HPD) and HyperlinkExternalPageDestination (HEPD).

The HPD object allows setting a custom name for the page destination, but HEPD doesn’t. It just uses the default naming convention, and it also doesn’t check if the destination already exists but creates duplicates with the same name.

Does anyone have any suggestions as to how to deal with this? If I run my script multiple times, it generates all HEPDs over and over, resulting in 1000’s of them. I don’t want to have to clean them up first every time I run the script, but rather check if an HEPD exists, and only create it if it doesn’t. That’s what I do with HPDs and it works nicely because I can find it by name.

Thanks for any insights you might have!

When you create an externalPageDestination you can set its name property:

destination = app.activeDocument.
  hyperlinkExternalPageDestinations.add ([External Page Object], {
    name: 'qwerty',
  });

As to avoiding duplicates, create a simple persistent look-up table of existing HEPDs. Then each time you want to add a new HEPD you first check whether the name exists. If it doesn’t, add the HEPD and add its name to the look-up table.

Thanks so much for the quick response Peter! This is exactly what I’m doing, but the name gets ignored when creating an HEPD. It automatically assigns an internal name, which I won’t be able to reconstruct, so I won’t be able to look up the page by name.

It works for HPDs exactly like you say, which is nice because it lets me look up the HPD by name.

So for some reason HEPDs and HPDs work differently which is a shame.

I’m reluctant to create a persistent look-up table as I feel this shouldn’t be needed.

But you have given me another idea: I’ve now assigned each HEPD a label instead of a name, and that works! So now I can look up the object by label instead of name, I just had to create the function to do that myself, but that’s easy.

Thanks for your help!

2 Likes