Skip to main content
Loic.Aigon
Legend
June 12, 2009
Question

JS CS3 : Hyperlinks.add(y,z) always recreates the same object :-(

  • June 12, 2009
  • 1 reply
  • 848 views

Hi,

I am trying to create hyperlinks from an index. The command works fine except that doc.hyperlinks.add(source,destination) always rewrites the former one. They don't stack and I need them to do this way.

Could you help ?

I write this function :

function hyperlien(src,dest)
{
    app.findTextPreferences.findWhat=src.contents;
    //var txtsrc = doc.hyperlinkTextSources.add(src);
    var txtsrc = doc.hyperlinkTextSources.add(doc.pageItems.item("index").findText()[0]);
    var pgdest = doc.hyperlinkPageDestinations.add();
    pgdest.destinationPage = dest;
    with(doc.hyperlinks.add (txtsrc,pgdest))
    {
        name = src.contents;
        visible = false;
    }
    app.select(NothingEnum.nothing, undefined);
}

and calls it this way :

hyperlien(app.selection[0],myPage);

according app.selection[0] is text, myPage is defined on top as:

var sel=app.selection[0];
var myFrame = app.selection[0].parentTextFrames[0];
var myPage = myFrame.parent;

the text is on a page but I try to apply the hyperlinks to the same text in the index. Hence I set my source as doc.pageItems.item("index").findText()[0]

Hope you can help.

Thanks Loic

This topic has been closed for replies.

1 reply

Harbs.
Legend
June 12, 2009

Each hyperlink source can only be used once. That's how they work...

Shared hyperlink destinations can be used as many times as you need,

but you can only create them once...

Also, you can't name two of any aspects of hyperlinks the same name.

(I.e. You can't have two hyperlink destinations with the same name.)

Harbs

Loic.Aigon
Legend
June 12, 2009

Hi Harbs,

Thanks a lot for answering.

The fact is I change my selection all the time and then relaunch the script. It means that app.selection[0] should be always a different text source.

I mean :

considering this text :

scin hent vullaore consed magna faciliquam zzrit la consenit lorem dio od magna accumsandre feu feuguerostio endre dolestrud dolesen issequi ssissisi.
Utpat. Lorperit atie dionullute modignim dunt in exer

I select vullaore then execute the script. I want it to hyperlink vullaor.

Then once it's done, I select lorem and launch the script once again. So I expect this time the script takes lorem as source.

Etc.

If I use dummy datas such as hyperlien(app.selection[0], pg[0]) in a other script, it runs well (hyperlinks are stacked). But when I intend to use it in my global script with the real inputs, hyperlinks don't stack anymore.


It's like something were persistent after the script :-(

Hope to find the trick.

Loic

Harbs.
Legend
June 12, 2009

I'm not sure I understand what you mean by "stacked".

Harbs