4 Replies Latest reply on Aug 18, 2010 5:02 PM by nickthenick

    [AS] How to make cross reference at insertion point

    nickthenick

      Hi,

       

      I have a book ("indb") including several documents with several "anchors"

      (german translation: "Textanker") where cross references from different documents are linked to.

      What I already got is to reference all anchors and collect them in a list.

       

      Now I would like to make a new cross reference at the insertion point

      in a text frame of the active document - can't get it to run :-(

       

      Is anybody out there who can post a AS-sample doing this?

       

      Thanks in advance!

       

       

      Here is the reference to an already existing anchor:

       

      {hyperlink text destination id 44155 of document "kapitel 2.indd" of application "Adobe InDesign CS4"}

       

      The code I tried to make a new cross reference looks like this - but of course doesn't work:

       

      tell application "Adobe InDesign CS4"

       

      tell active document

      make new hyperlink with properties {name:"new hyperlink", destination:hyperlink text destination id 44155 of document "kapitel 2.indd"}

       

       

      end tell

       

      end tell


        • 1. Re: [AS] How to make cross reference at insertion point
          sstanleyau Level 4

          To make a hyperlink, you must provide both a destination and a source. In this case, the source will need to be a suitable "cross reference source".

          • 2. Re: [AS] How to make cross reference at insertion point
            nickthenick Level 1

            Thank you for your answer.

            Yes, thats what the scripteditor says too,

            but I'm just not able to find out how to write the code ...

             

            The following code looks for an existing hyperlink "made by hand" and calls it's properties:

             

            tell application "Adobe InDesign CS4"

                 tell active document

                      set crossReferenceList to first hyperlink

                      set hyperlinkProps to properties of crossReferenceList

                 end tell

            end tell


            "crossReferenceList" gives:

            hyperlink id 44238 of document "kapitel 1.indd" of application "Adobe InDesign CS4"

             

            "hyperlinkProps" gives:

             

            {id:44238, border color:black, highlight:none, border style:solid, hidden:false, destination:hyperlink text destination id 44159 of document "kapitel 3.indd" of application "Adobe InDesign CS4", source:cross reference source id 44237 of document "kapitel 1.indd" of application "Adobe InDesign CS4", parent:document "kapitel 1.indd" of application "Adobe InDesign CS4", index:1, name:"Querverweis 3", object reference:hyperlink id 44238 of document "kapitel 1.indd" of application "Adobe InDesign CS4", label:"", visible:false, width:thin}

             

            Can anyone help please?

            • 3. Re: [AS] How to make cross reference at insertion point
              sstanleyau Level 4

              This should give you somewhere to start:

               

              tell document 1

              set theDest to make hyperlink text destination with properties {name:"Some name", destination text:<a reference to the relevant text>}

              set theSource to make cross reference source with properties {name:"Some name",source text:< reference to the relevant text>}

              make hyperlink with properties {source:theSource, destination:theDest, visible:true, highlight:invert, width:thick, border color:dark green, border style:dashed, name:"Whatever" }

              end tell

              1 person found this helpful
              • 4. Re: [AS] How to make cross reference at insertion point
                nickthenick Level 1

                Thanks a lot - got it now!

                 

                Maybe it could be helpful for others to look at your answer  

                with the placeholders replaced by "real" strings as it was hard for me

                to figure out the right form:

                 

                tell document 1

                 

                set theDest to make hyperlink text destination with properties {name:"Some name", destination text:<a reference to the relevant text>}

                this line for example looks like this =>

                set theDest to make hyperlink text destination with properties {name:"Some name", destination text:insertion point 902 of story id 44083 of document "kapitel 3.indd" of application "Adobe InDesign CS4"}

                set theSource to make cross reference source with properties {name:"Some name",source text:< reference to the relevant text>}

                this line for example looks like this =>

                set theSource to make cross reference source with properties {name:"Some name", source text:cursorPosition, applied format:cross reference format id 44305 of document "kapitel 1.indd" of application "Adobe InDesign CS4"}

                 

                where "cursorPosition" was defined before by

                set cursorPosition to object reference of selection

                (the cross reference source needs the applied format reference too)

                 

                make hyperlink with properties {source:theSource, destination:theDest, visible:true, highlight:invert, width:thick, border color:dark green, border style:dashed, name:"Whatever" }

                this line for example looks like this =>

                make hyperlink with properties {source:theSource, destination:hyperlink text destination id 44184 of document "kapitel 3.indd" of application "Adobe InDesign CS4", border color:black, highlight:none, border style:solid, hidden:false, visible:true, width:thin}

                 

                 

                end tell