6 Replies Latest reply on May 26, 2014 7:27 AM by ThinkingThings

    Problem Linking HyperLink 3 Images on Same Cell Text Line. Need hero.

    ThinkingThings Level 1

      Hello Friends,

       

      I need a hero, please. VB.NET, CS6. I am trying to add hyperlinks to 3 images. Here's the code (it's VB.NET but the logic should be easy to understand)

       

              If imageFileName IsNot Nothing Then

                  Dim rect As ID.Rectangle = curTextItem.Rectangles.Add() : With rect

                      .Name = imageFileName

                      .GeometricBounds = geoBounds

                      .Place(imageFileName)

                      .ClearObjectStyleOverrides()    'needed to eliminate drop shadow

                      .StrokeWeight = 0               'needed to eliminate stroke

                      .Fit(idFitOptions.idProportionally)

                      .Fit(idFitOptions.idFrameToContent)

                      .Select()

                  End With

                  If imageLink IsNot Nothing Then

                      Dim myHyperlinkURL = aDoc.HyperlinkURLDestinations.Add(imageLink)

                      Dim myHyperlinkSource = aDoc.HyperlinkPageItemSources.Add(rect)            

                      Dim myHyperlink = aDoc.Hyperlinks.Add(myHyperlinkSource, myHyperlinkURL)

                      myHyperlink.Visible = False

                  End If

              End If


      FYI:  curTextItem is a cell.Text object.

       

      When I add them without the hyperlinks, everything works fine (comment out red lines). However, when I try to add the first hyperlinkSource it errors with:

       

      A first chance exception of type 'System.InvalidCastException' occurred in InDesign Scripting.exe

      Additional information: Unable to cast COM object of type 'System.__ComObject' to interface type 'InDesign.PageItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{D7D2C130-D321-11D1-AAA2-00C04FA349C7}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

       

      I've tried just about every imaginable object reference to replace "rect" (except the "right" one) to make this work. If I choose to use "HyperlinkTextSources" instead of "HyperlinkPageItemSources" I can successfully link the first source by using  "aDoc.HyperlinkTextSources.Add(curTextItem.Texts.LastItem) but when it gets to the second source it errors with:

       

      "The object you have chosen is already in use by another hyperlink."

       

      I've been at this for about a day. If I were a smarter guy I might have given up a while ago, but I am stubborn. I know that I am missing something simple. You'll probably hear me smack my head from wherever you are when I get the answer. Please help.

       

      Thank you kindly,

       

      -TT