Skip to main content
Participating Frequently
September 28, 2009
Question

Hyperlink Script

  • September 28, 2009
  • 2 replies
  • 2909 views

I am new to scripting but I have a problem that seems to be a good candidate for a script.

I am working on a catalog that is being converted from Pagemaker 7 to Indesign CS4. The conversion has corrupted all the text anchors and now have to be redone. The hyperlinks are still there but the anchors all point to the beginning of the text frame.

There are about 40 sections with about 150 links in each section. This is way too many to do by hand so I figured a script would be just the thing.

The catalog is broken down into a seperate file for each section which holds one unit for each section. The first two pages for each section shows every part inside that unit and the rest of the pages are a list of part numbers and descriptions. The image for each piece has a text frams as a label which is a hyperlink to the part number and description later in the document.

I think it would be done best in two scripts. (JS or VBS doesn't matter) The first script would be simple. I would highlight a part number and run the script which would create a Hyperlink Destination (Text Anchor) with the same name as the highlighted text. Simple, but it would cut down on the number of clicks considerably.

The second script would use the existing Hyperlinks in the document and link them to the new destinations. Each section covers a single unit number, such as 40 or 105. The unit number is the first half of the part number. The second half is the piece number, which is the first 3 numbers in the name of the Hyperlink. Thus Unit 40 piece 304 would have a part number of 40304, the name of the text anchor. All of the part numbers in that section will have the same unit number.

Basically it would work like this:

  1. Highlight unit number
  2. Run script
  3. Script takes first hyperlink and changes destination to (Unit Number) + (First 3 numbers of Hyperlink Name)
  4. Repeat with all remaining hyperlinks

So if the unit number was 40 and the first Hyperlink was named 120-2 then it would point to the text anchor named 40120.

This would take VERY long to do by hand and I would appreciate any help that you could give me with this problem. If you have heard about this anchor corruption issue before and know how to avoid it, that would also be helpful.

This topic has been closed for replies.

2 replies

Participating Frequently
October 21, 2009

OK. I don't know how to do this in VBS and it's been a long time since I have programmed in Visual Basic so here is what I want to do in pseudocode.

ModelNumber = CurrentSelection

For MyCounter = 1 to NumberofHyperlinks      'or number of text frames

     Set CurrentItem to ListofItems(MyCounter)
          If CurrentItem.Hyperlink = TRUE then
               If exist TextAnchor = ModelNumber + CurrentItem.Name(3) then
                    CurrentItem.HyperlinkDestination = ModelNumber + CurrentItem.Name(3)
               End If
          End If
Next

So basically I will highlight the model number on the first page and it will pick that up. It will then cycle through all the hyperlinks in the document, or all the text frames if that's easier, and set the destination to an anchor with a name = ModelNumber + First 3 letters in the hyperlink's name. If there is no Hyperlink, it will just skip it. If there is no anchor with the proper name, it will also skip it.

It would only need to process items on the current page and I would change the page manually before running it again.

Can anyone help rewrite this into actual VBS code that I can use? or even Javascript?

Jongware
Community Expert
Community Expert
October 21, 2009

Sorry, Shaun, but it's still not entirely clear what should happen and when ...

Can you post a screen shot of what the document looks like now? A simple snippet of a relevant portion ought to be enough.

Just FYI, this short javascript will show you the names and textual contents of existing hyperlinks:

var array = new Array;
for (a=0; a<app.activeDocument.hyperlinks.length; a++)
array.push(app.activeDocument.hyperlinks.name+" -> "+app.activeDocument.hyperlinks.source.sourceText.contents);
alert (array.join('\n'));

(if the list is so long it appears only partly, just press "Enter").

Hyperlinks consist of two parts: a hyperlink source -- the actual text that gets the link, and may be visible with an outline rectangle, and a hyperlink destination -- an invisible marker with a name. So far, I understand the hyperlinks are already in place but they point to the wrong anchors -- correct?

Participating Frequently
October 22, 2009

Yes, that is correct. These files were originally created in Pagemaker 7, but when converted to InDesign the destinations for all of the hyperlinks were messed up. They now all point to the same place. If I delete the destinations, recreate them, and point the source to the new destination it works again. The problem is that I have about 13,000 hyperlinks spread across about 90 files. A large task.

I'm not sure what to take a screenshot of but here is a description. The first two pages consist of pictures of parts. Each picture has a text box containing the 3 digit part number (ie 253, 537, etc). This text box is the source for a hyperlink which has the same name as the 3 digit number, plus -1, -2 etc if there are more than one of the same number. The destination is a number in a long list that is spread through several threaded text frames. The name of the destination is the model number (like 45) plus the 3 digit part number (like 853). So the name would be 45853.

I can create the destinations by hand pretty easily but the linking is tedious. Do you understand now? Any more questions?

Also, your javascript snippet did not work. It returned an error:

Error Number: 55

Error String: Object does not support the property or method 'sourcetext'

Line: 3

Source: array.push(app.activeDocument.hyperlinks.name+" -> "+app.activeDocument.hyperlinks.source.sourceText.contents);

Robert at ID-Tasker
Legend
September 30, 2009

hi

you can contact me on priv - zapraszam na priv

robin

www.adobescripts.pl

Participating Frequently
October 14, 2009

It turns out that he was not able to help me.

Does anyone else have an idea?

Participating Frequently
October 19, 2009

Any thoughts from anyone, please?