Skip to main content
okravetz_Isobar
Participant
February 28, 2017
Answered

InDesign Crashing when trying to add hyperlink to another document

  • February 28, 2017
  • 2 replies
  • 1275 views

I'm running the following code on the latest version of InDesign CC on Windows 7.

I'm trying to create a list of cross-references to a collection of pre-grepped TextFrames--myTextFrames--from across the documents of a book. The cross-reference text and link is meant to be added in the text frame whose contents are currently selected in the Index document--activeDoc.

The app crashes on line 49, at the hyperlink.add(). Any ideas why?

function main()

{

    var myBook = app.activeBook;

    var myDoc, myTextFrames, myDestinations, i;

   

    for (i = 1; i < myBook.bookContents.length; i++)

    {

        myDoc = app.open(File(myBook.bookContents.fullName), false);

        // ... getTextFrames() happens here

        myDestinations = createDestinations(myDoc, myTextFrames);

        createHyperlinks(myDoc, myDestinations);   

        myDoc.close(SaveOptions.YES);

    }

}

// Create destinations

function createDestinations(myDoc, /* Array[TextFrame] */ myTextFrames)

{

    var i, myParagraph, myLinkName, myDestinations = [];

   

    for (i = 0; i < myTextFrames.length; i++)

    {

        myInsertionPoint = myTextFrames.paragraphs[0].insertionPoints.firstItem();

        myLinkName = myTextFrames.paragraphs[0].contents;

       

        myDestinations.push(myDoc.paragraphDestinations.add(myInsertionPoint, {name: myLinkName}));

    }

    return myDestinations;

}

// Create hyperlinks

function createHyperlinks(myDoc, /* Array[paragraphDestination] */ myDestinations)

{

    var i, mySource, mySourceText, myParagraphDestination, myLink, myInsertionPoint;

    var xRefForm = myDoc.crossReferenceFormats.item('Full Paragraph');

    var activeDoc = app.activeDocument;

       

    for (i = 0; i < myDestinations.length; i++)

    {

        myInsertionPoint = app.selection[0].insertionPoints.lastItem();       

        mySource = activeDoc.crossReferenceSources.add(myInsertionPoint, xRefForm);

        myParagraphDestination = myDoc.paragraphDestinations.itemByName(myDestinations.name);

        myLink = activeDoc.hyperlinks.add(mySource, myParagraphDestination, {name: myDestinations.name});

    }

}

Thank you,

Oren

This topic has been closed for replies.
Correct answer okravetz_Isobar

It turns out the file itself might have been corrupt. I saved to IDML and back to INDD again and it seemed to work.

2 replies

Participant
February 26, 2018

i am having same problem on a mac. i thought it was because of recent OSX update. this has been a problem in the past/previous versions. will try your work around. thanks!

okravetz_Isobar
okravetz_IsobarAuthorCorrect answer
Participant
May 1, 2017

It turns out the file itself might have been corrupt. I saved to IDML and back to INDD again and it seemed to work.