Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

hyperlinkTextSources from hyperlinkTextDestinations text

Explorer ,
May 15, 2013 May 15, 2013

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

TOPICS
Scripting
2.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , May 18, 2013 May 18, 2013
Translate
New Here ,
May 15, 2013 May 15, 2013

-- 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 16, 2013 May 16, 2013

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 18, 2013 May 18, 2013
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 19, 2013 May 19, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 19, 2013 May 19, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 20, 2013 May 20, 2013

Yes, it is

Thank you Trevor

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 20, 2013 May 20, 2013

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.source.sourceText;

                hypDestination = myHyperlinks.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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 20, 2013 May 20, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 20, 2013 May 20, 2013
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines