1 Reply Latest reply on May 1, 2017 8:58 AM by okravetz_Isobar

    InDesign Crashing when trying to add hyperlink to another document

    okravetz_Isobar

      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[i].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[i].paragraphs[0].insertionPoints.firstItem();
              myLinkName = myTextFrames[i].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[i].name);
              myLink = activeDoc.hyperlinks.add(mySource, myParagraphDestination, {name: myDestinations[i].name});
          }
      }
      

       

      Thank you,

      Oren