10 Replies Latest reply on Oct 26, 2009 6:55 AM by Shaun_Poland

    Hyperlink Script

    Shaun_Poland

      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.

        • 1. Re: Hyperlink Script
          AdobeScripts Level 3

          hi

           

          you can contact me on priv - zapraszam na priv

           

          robin

           

          www.adobescripts.pl

          • 2. Re: Hyperlink Script
            Shaun_Poland Level 1

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

            Does anyone else have an idea?

            • 3. Re: Hyperlink Script
              Shaun_Poland Level 1

              Any thoughts from anyone, please?

              • 4. Re: Hyperlink Script
                Shaun_Poland Level 1

                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?

                • 5. Re: Hyperlink Script
                  [Jongware] Most Valuable Participant

                  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[a].name+" -> "+app.activeDocument.hyperlinks[a].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?

                  • 6. Re: Hyperlink Script
                    Shaun_Poland Level 1

                    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[a].name+" -> "+app.activeDocument.hyperlinks[a].source.sourceText.contents);

                    • 7. Re: Hyperlink Script
                      [Jongware] Most Valuable Participant

                      Hmm. Like Robin, I have no idea how to attack this one.

                       

                      The javascript snip works just fine -- for me it does. It probably just doesn't agree with the "partial" or mismatched hyperlinks in your document.

                      links.PNG

                      • 8. Re: Hyperlink Script
                        Shaun_Poland Level 1

                        I tried it on a file where I fixed the links and is still doesn't work. It may be due to the fact that you are using URL destinations and I am using Text Anchors within the same document.

                         

                        I just want the script to go through the list of hyperlink sources and point them to the proper destinations, text anchors with easy to figure out names.

                         

                        Also, Robin said he knew how to do it and offered to write me a script for it, but then he got too busy with work, so I came back here.

                        • 9. Re: Hyperlink Script
                          AdobeScripts Level 3

                          Hmm. Like Robin, I have no idea how to attack this one.

                           

                          I've never said that I can't do this or I don't know how to do this

                          I only don't have time to make this for free ...

                           

                          There is a mess with Hyperlinks in his files - all of them should be deleted and created again - easiest way . Each TF from first page have numerc contents which could be used to build Source and Destionation (on other pages - in text) of Hyperlink.

                           

                          robin

                           

                          www.adobescripts.co.uk

                          • 10. Re: Hyperlink Script
                            Shaun_Poland Level 1

                            Well, anyone else want to take a shot at it?