Thread View: adobe.scripting.indesign
8 messages
8 total messages
Started by Rick_Quatro
Thu, 18 Dec 2008 17:16
[CS4 JavaScript] Cross references
Author: Rick_Quatro
Date: Thu, 18 Dec 2008 17:16
Date: Thu, 18 Dec 2008 17:16
7 lines
769 bytes
769 bytes
Hello All, Is the new cross reference feature of InDesign CS4 scriptable? In other words, is it possible to add and edit cross references with JavaScript? Thanks in advance. Rick Quatro rick at frameexpert dot com 585-659-8267
Re: [CS4 JavaScript] Cross references
Author: Dave_Saunders
Date: Thu, 18 Dec 2008 17:42
Date: Thu, 18 Dec 2008 17:42
15 lines
1648 bytes
1648 bytes
Yes.
But finding them in the Object Model is an interesting challenge because they're not called cross references, they're called hyperlinks. Here's a snippet of code I used to make a cross reference using a format I called "Page Number Only" that I had previously created (manually in the UI):
var destination = doc.hyperlinkTextDestinations.add(dest, {name:termName});
var xRefForm = doc.crossReferenceFormats.item("Page Number Only");
var sourceText = getSource(para);
if (sourceText == null) {return } // I don't think this can happen, but just in case
var source = doc.crossReferenceSources.add(sourceText, xRefForm);
var myLink = doc.hyperlinks.add(source, destination);
myLink.visible = false;
So, it is very similar to making any other kind of hyperlink. First, make your destination (dest in that first statement is a text reference into my document) then make a cross reference source, then make a hyperlink joining the two together.
Dave
Re: [CS4 JavaScript] Cross references
Author: Rick_Quatro
Date: Thu, 18 Dec 2008 19:59
Date: Thu, 18 Dec 2008 19:59
5 lines
672 bytes
672 bytes
Hi Dave, Thanks for the code. This should get me started. Rick
Re: [CS4 JavaScript] Cross references
Author: Rick_Quatro
Date: Thu, 18 Dec 2008 20:50
Date: Thu, 18 Dec 2008 20:50
16 lines
1144 bytes
1144 bytes
Hi Dave,
In this line:
var destination = doc.hyperlinkTextDestinations.add(dest, {name:termName});
what does "dest" refer to? Is it a paragraph object? I actually think I want to do this:
var destination = doc.paragraphDestinations.add(dest);
The documentation says that dest is Text, but I am not sure how to specify the paragraph that I want the cross reference to point to.
On a related point, I would want to know how to see if a ParagraphDestination already exists for a particular paragraph object.
Thanks,
Rick
Re: [CS4 JavaScript] Cross references
Author: Dave_Saunders
Date: Thu, 18 Dec 2008 21:01
Date: Thu, 18 Dec 2008 21:01
13 lines
1286 bytes
1286 bytes
You can specify the paragraph in any of the various ways that a paragraph can be referenced: myFinds[j].paragraphs[0]; myStory.paragraphs[16]; app.selection[0].paragraphs[0]; it all depends on the technique you're using to pick out paragraphs. I never noticed pargraphDestinations when I was researching this. I probably could have used that instead, although in my case I was pointing at words within paragraphs. That could matter for long paragraphs that might span from one page to another. I'm not sure off the top of my head with how to help with whether or not a paragraph destination already exists. Does it do any harm to make another one? Not sure. Dave
Re: [CS4 JavaScript] Cross references
Author: Rick_Quatro
Date: Thu, 18 Dec 2008 21:46
Date: Thu, 18 Dec 2008 21:46
7 lines
1140 bytes
1140 bytes
Yes, this works fine, where oPgf is a paragraph object, and oDoc is the document object: var destination = oDoc.paragraphDestinations.add(oPgf,name:"abc"}); Do paragraphs in InDesign have a unique id or serial number? If so, I could use this for the name parameter. That way, if I want to point to a paragaph, I could query the ParagraphDestinations using the paragraph's id to see if a ParagraphDestination already exists for that paragraph. Thanks for your help!
Re: [CS4 JavaScript] Cross references
Author: Dave_Saunders
Date: Thu, 18 Dec 2008 22:00
Date: Thu, 18 Dec 2008 22:00
3 lines
822 bytes
822 bytes
Not unique. A paragraph is a specially recognized text object identified by its start and end indexes within a story. Edit any part of the story prior to the paragraph and those indexes change. Dave
Re: [CS4 JavaScript] Cross references
Author: Rick_Quatro
Date: Tue, 06 Jan 2009 20:07
Date: Tue, 06 Jan 2009 20:07
25 lines
1682 bytes
1682 bytes
I have the basics of cross-references; now I want to insert some external cross-references. Here is the basics of what I have working.
// destDoc = destination document.
// xrefDoc = adding cross-reference to this doc.
// Get a pre-existing destination from the destination document.
var dest = destDoc.paragraphDestinations.item('2916');
// Get the cross-reference format.
var xrefFmt = xrefDoc.crossReferenceFormats.item('Full Paragraph & Page Number');
// Add the cross-reference source.
var source = xrefDoc.crossReferenceSources.add(app.selection[0],xrefFmt);
// Add the cross-reference.
var xref = xrefDoc.hyperlinks.add(source,dest);
This works; however, I am trying to find a way to add a cross-reference without first getting the ParagaphDestination from the destination document. I know the name of the destination document and I know the name of the destination, and I would like to build the external cross-reference without having to open the destination document. Does anyone know if this is possible? Thanks in advance.
Rick Quatro
585-659-8267
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads