9 Replies Latest reply on May 20, 2013 1:46 PM by Trevorׅ

    hyperlinkTextSources from hyperlinkTextDestinations text

    foredit

      Hi Scripters, big question!!!

      With two documents open, I have some hyperlinkTextDestinations previously created by text selections.

      Now want to create hyperlinks with hyperlinkTextSources refering to the same text used for anchors.

      Trying for hours several solutions and roaming the web with no success, here's a test script:

       

       

      var myLink = app.documents[0].hyperlinkTextDestinations[0].destinationText.select();

      var mySource = app.documents[0].hyperlinkTextSources.add(myLink);

      var myAnchor = app.documents[1].hyperlinkTextDestinations[0];

      app.documents[0].hyperlinks.add(mySource, myAnchor);

       

       

      The prob is that i get (line 1) an insertionPoint instead a text selection.

       

      Any indications appreciated,

      regards

        • 1. Re: hyperlinkTextSources from hyperlinkTextDestinations text
          SuriyaRevathi Rengan

          -- by using apple script -> u converted this into java script

          eg :  set mydoc to active document -> apple script

              var myDoc = app.activeDocument -> java script

           

           

          select text of selection

                          set SourceText to item 1 of selection as string

                          set hrperlnk to hyperlinks

                          set LnkTxt to 0

                          set HyperLnkTxt to hyperlink text sources

                          repeat with i from 1 to count of HyperLnkTxt

                              set HyperLnkSrc to item i of HyperLnkTxt

                              set src to contents of source text of HyperLnkSrc

                              if src is equal to SourceText then

                                  set LnkTxt to 1

                                  set HyperLnkSrc to item i of HyperLnkTxt

                                  exit repeat

                              end if

                          end repeat

          • 2. Re: hyperlinkTextSources from hyperlinkTextDestinations text
            foredit Level 1

            Thank you SuriyaRevathi,

            but, if I've right understood your script, a selected text is my target (js line 1) not my starting point (it will be at js line 2)

            • 4. Re: hyperlinkTextSources from hyperlinkTextDestinations text
              foredit Level 1

              Thanks Trevor,

              very useful post confirming that looking for hyperlinkTextDesination it just gets an insertionPoint and not contents.

              I need to create bidirectional hyperlinks (text to note, note to text) this is why i want to transform an anchor in a source too.

              Now from this Select one or more characters after insertion point (thank you for reply) i will try.

               

              regards

              • 5. Re: hyperlinkTextSources from hyperlinkTextDestinations text
                Trevorׅ Adobe Community Professional

                Hi Foredit,

                 

                Remember you can only create bidirectional hyperlinks if each destination only has one source.

                Is that the case by you?

                 

                Trevor.

                 

                P.s. Please mark the other post as answered.

                • 6. Re: hyperlinkTextSources from hyperlinkTextDestinations text
                  foredit Level 1

                  Yes, it is

                   

                  Thank you Trevor

                  • 7. Re: hyperlinkTextSources from hyperlinkTextDestinations text
                    Trevorׅ Adobe Community Professional

                    Ok, here's a start

                     

                    See before and after screenshots

                    Read the warning

                     

                    Before:

                    Before Hyper.png

                     

                    After:

                    After Hyper.png

                     

                    Click the shots to see them clearly

                    The script:

                     

                    // Make new bidirectional hyperlinks from existing unidirectional ones
                    // By Trevor http://forums.adobe.com/thread/1212690?tstart=0
                    // WARNING ONLY WILL (IF LUCKY) WORK IF THERE ARE NO SOURCES IN THE NEW DESTINATION 
                    // MEENS THAT YOU CAN'T RUN IT TWICE
                    // BUT YOU CAN DO CTRL / OPTION Z TO UNDO
                    app.doScript("main()", ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Make Inverse Hyperlinks");
                    function main()
                        {
                            var doc= app.activeDocument,
                                   myHyperlinks =doc.hyperlinks.everyItem().getElements(),
                                   l = myHyperlinks.length;
                            var hypSource, hypDestination, newDestinationName, hdps, hypDestinationPos, newDestination, newSource, newHL;
                            while (l--)
                                {
                                    hypSource = myHyperlinks[l].source.sourceText;
                                    hypDestination = myHyperlinks[l].destination.destinationText;
                                    newDestinationName = hypSource.contents;
                                    hdps = hypDestination.parentStory;
                                    hypDestinationPos = Math.min(hdps.texts.itemByRange (0, hypDestination.insertionPoints[0].index).words.length - 1, 0);
                                    newDestination = doc.hyperlinkTextDestinations.add(hypSource);
                                    newDestination.name = newDestinationName + " ... " + newDestination.id + "_";
                                    newSource =  doc.hyperlinkTextSources.add(hypDestination.paragraphs[0].characters.itemByRange(0,-1));
                                    newHL = doc.hyperlinks.add(newSource, newDestination, {});
                                    newHL.name = newSource.sourceText.contents.slice(0, Math.min(20, newSource.sourceText.contents.length)) + " ... " + newHL.id + "_";
                                    //newHL.source.sourceText.appliedCharacterStyle="2";
                            }
                        }
                    

                     

                    Trevor

                    • 8. Re: hyperlinkTextSources from hyperlinkTextDestinations text
                      foredit Level 1

                      Interesting script i'll study for sure but it assume hyperlinks and anchors already in the document.

                      Workin' on epub with endnotes i've previously created all anchors with the same name in both documents (text document and notes document).

                      From this scenario i've to create hyperlinks from text to note and back again.

                      Starting from insertionPoint, by me, solution could be to select anchor text and add hyperlink matching anchor's name.

                       

                      Exporting epub there would be something like this in xhtml documents.

                       

                      text.xhtml

                      <a id="n1c1" href="notes.xhtml#n1c1">1</a>

                       

                      notes.xhtml

                      <a id="n1c1" href="text.xhtml#n1c1">1</a>

                       

                      I hope not confusing you

                      best regards

                      • 9. Re: hyperlinkTextSources from hyperlinkTextDestinations text
                        Trevorׅ Adobe Community Professional

                        Hi Foredit,

                         

                        I didn't realize that you were working on an epub I would have to look into that and it would take me quite a bit of time.

                         

                        As you are doing try use the imformation from your recent treads to figure it out and start more threads as required.

                         

                        If you get desperate then I'm always happy to take a job for money

                         

                        Regards

                         

                        Trevor