4 Replies Latest reply: Aug 17, 2012 11:25 AM by AndreeaPicos RSS

    HELP... how to determine when an object has a hyperlink??

    AndreeaPicos

      anybody help me plss??

       

      1.- Add a hyperlink a object in InDesign CS2

          select the object (textframe. image), right click > interactive > New Hyperlink

       

       

      2.-in visual studio (vb)

       

          I try...

         

         

          For Each ObjTxtFrame In IdDoc.TextFrames

       

              'how to determine when an object has a hyperlink??

       

       

          Next

       

       

          And

       

           For Each objHyperlink In IdDocActual.Hyperlinks

       

       

              MsgBox(objHyperlink.id) ' OK

       

           Next

       

       

      I want to know the id of the object that has the hyperlink

       

       

      ayuda por favor

        • 3. Re: HELP... how to determine when an object has a hyperlink??
          [Jongware] CommunityMVP

          I don't do VB but to "get the id of the object that has the hyperlink" this works in Javascript:

           

          objHyperLinks = app.activeDocument.hyperlinks;
          for (i=0; i<objHyperLinks.length; i++)
                    if (objHyperLinks[i].source instanceof HyperlinkPageItemSource)
                              alert (objHyperLinks[i].source.sourcePageItem.id);
          

           

          (which, very helpfully, tells me that "227" is its id. Why do you need just the id? There are very few circumstances where it's useful (actually, see below for one, although it can be rewritten without using 'id' at all).)

           

          The trick here is that the source property of a hyperlink points to the link properties of the item that's hyperlinked, through a second property sourcePageItem. The source type can be one of several: Cross Reference (which I haven't used yet), HyperlinkTextSource (a regular hyperlink in a text), and HyperlinkPageItemSource, which can be any valid page item. It's the latter you are interested in, so it seems, so that's what it checks for.

           

          The inverse -- given an object and finding what it links to -- is one of the more tricky operations. An object does not define a 'hyperlink'; you need to check its id against the entire list of links.

           

          This Javascript, when run with a page item selected, will show the URL if it is a hyperlink to an URL, or will end silently when it is not.

          Again, it uses the Javascript-only construction 'instanceof', and I cannot recall if there is a similar command for VB.

           

          objSelection = app.selection[0];
          objHyperLinks = app.activeDocument.hyperlinks;
          
          for (i=0; i<objHyperLinks.length; i++)
          {
                    if (objHyperLinks[i].source instanceof HyperlinkPageItemSource)
                    {
                              if (objHyperLinks[i].source.sourcePageItem.id == objSelection.id)
                              {
                                        alert (objHyperLinks[i].source.sourcePageItem.id+" = "+objHyperLinks[i].destination.destinationURL);
                                        break;
                              }
                    }
          }
          
          • 4. Re: HELP... how to determine when an object has a hyperlink??
            AndreeaPicos Community Member

            Well I'll tell you, I need the coordinates of the object (TextFrame, image) has a hyperlink, and I can not get the hyperlink GeometricBounds

             

            with the id of the object, I can extract GeometricBounds

             

            I will try with your code. muchas gracias