5 Replies Latest reply on Nov 18, 2010 9:45 AM by Reedsburg Rob-9MT11Y

    looking to hyperlink two character styles

    Reedsburg Rob

      I'm very new to scripting and even the concept of using scripts. I've got InDesign CS4. I have several documents with endnotes (some with as many as 130). I'm working on exporting them all as ePub files. I've already got all of their numbers and the footnote numbers in the text assigned to a specific character style. What I'm wondering is if it is possible to create a script to link each instance of one character style to its corresponding number in another character style, or does anyone know of a script that has already been created to do this?

       

      As an example, it would find all of the numbers that have been assigned a character style of "footnote" in the text and link them to the same numbers (1 to 1, 2 to 2, etc.) with the character style "footnote destination". The end product then would allow a user to click on a footnote number, be taken to the note, then click on that note's number and be taken back to where they left off in the book.

       

      Any ideas?

       

      Rob

        • 1. Re: looking to hyperlink two character styles
          [Jongware] Most Valuable Participant

          Piece of cake.

           

          That is, I get errors when I try to run this script twice. I might want to look into fixing that ...

           

          app.findGrepPreferences = null;
          app.findGrepPreferences.appliedCharacterStyle = "footnote";
          app.findGrepPreferences.findWhat = "\\d+";
          
          sourceList = app.activeDocument.findGrep();
          
          app.findGrepPreferences = null;
          app.findGrepPreferences.appliedCharacterStyle = "footnote destination";
          app.findGrepPreferences.findWhat = "\\d+";
          
          destList = app.activeDocument.findGrep();
          
          if (sourceList.length != destList.length)
          {
               alert ("This doesn't match -- please review\r\rSource: "+sourceList.length+"\rDest: "+destList.length);
               exit(0);
          }
          
          for (i=0; i<sourceList.length; i++)
          {
               app.activeDocument.hyperlinks.add(app.activeDocument.hyperlinkTextSources.add(sourceList[i]), app.activeDocument.hyperlinkTextDestinations.add(destList[i]));
               app.activeDocument.hyperlinks.add(app.activeDocument.hyperlinkTextSources.add(destList[i]), app.activeDocument.hyperlinkTextDestinations.add(sourceList[i]));
          }
           
          

          • 2. Re: looking to hyperlink two character styles
            Reedsburg Rob Level 1

            Holy Cow, that was awesome! But it stopped at 51 links (up to footnote 26) and gave me this message:

             

            JavaScript Error!

             

            Error Number 79111

            Error String: The object you have chosen is alrady in use by another hyperlink.

             

            I believe that have some problem with line 18:

             

            app.activeDocument.hyperlinks.add(app.activeDocument.hyperlinkTextSources.add(sourceList[i]), app.activeDocument.hyperlinkTextDestinations.add(destList[i]));

            Any ideas?

             

            Rob

            • 3. Re: looking to hyperlink two character styles
              [Jongware] Most Valuable Participant

              Yeah -- oddly, that's exactly the error I get after running it twice on a test file -- even when I deleted all hyperlinks I could see.

               

              I have no idea what it's complaining about ... Clearly, there are no hyperlinks in that place before the script adds one, and (also) clearly, it ought to add them only once to both target and destination!

               

              Any suggestions from one of the other guys (& gals) are appreciated

              • 4. Re: looking to hyperlink two character styles
                Harbs. Level 6

                You might  need to remove the sources (and destinations)...

                 

                app.docuemnts[0].hyperlinkTextSources.everyItem().remove();

                app.docuemnts[0].hyperlinkTextDestinations.everyItem().remove();

                 

                Harbs

                • 5. Re: looking to hyperlink two character styles
                  Reedsburg Rob-9MT11Y

                  Absolutely fantastic! I corrected the spelling for "documents" then put it in between the if and for statements and it worked like a charm. 5 hours worth of monotonous work done in under 15 seconds!

                   

                  Thanks a ton!

                   

                  Rob