Skip to main content
Participant
September 17, 2009
Question

Cross-reference destination

  • September 17, 2009
  • 2 replies
  • 908 views

Hi,

I would like to set destination for cross-reference to paragraph style like I do when I click on cross-reference options. On options screen I have a list of paragraph styles, but I don't get how to do that in script(JS).

Thnx

This topic has been closed for replies.

2 replies

ivan888Author
Participant
September 17, 2009

I finnaly achieved what I wanted. I did it in stupidest possible way, but it works. I iterated through all paragraphs and than if that paragraph had style that i was searching for I linked it with corss reference. Here is my code for 3 crossreferences I had to re-link:

var mydoc = app.documents.item(0);

for (var i=0; i<mydoc.textFrames.length; ++i) {
     var frame = mydoc.textFrames.item(i);
     for (var j=0; j<frame.paragraphs.length; ++j) {
          var ap=frame.paragraphs.item(j);
          if (ap.appliedParagraphStyle.name == "Highlight_p") {
               // One
               mydoc.hyperlinks.item("Cross-Reference").destination = mydoc.hyperlinkTextDestinations.add(ap);
          } else if ( ap.appliedParagraphStyle.name == "Highlight" ) {
               // Two
               mydoc.hyperlinks.item("Cross-Reference 1").destination = mydoc.hyperlinkTextDestinations.add(ap);
          } else if (ap.appliedParagraphStyle.name == "Highlight_o") {
               // Three
               mydoc.hyperlinks.item("Cross-Reference 2").destination = mydoc.hyperlinkTextDestinations.add(ap);
          }
         
     }
}

EDIT: I hope someone will find this usefull

ivan888Author
Participant
September 17, 2009

I came to conclusion that every crossreference has a hyperlink, and hyperlink has a destination. What I don't understand is how to make hyperlink's destinatio from paragraph style...

Peter Kahrel
Community Expert
Community Expert
September 17, 2009

> I came to conclusion that every crossreference has a hyperlink

Correct. For an example, see http://www.kahrel.plus.com/indesign/foot_to_end.jsx. The script uses cross-references to convert InDesign's footnotes to automatically numbered endnotes

Peter