Skip navigation
AndreeaPicos
Currently Being Moderated

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

Aug 15, 2012 6:37 PM

Tags: #hyperlink #cs2 #textframe

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

 
Replies
  • Currently Being Moderated
    Aug 16, 2012 1:31 AM   in reply to AndreeaPicos
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 3:33 PM   in reply to AndreeaPicos

    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;
                        }
              }
    }
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points