Skip to main content
ThinkingThings
Inspiring
May 25, 2014
Question

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

  • May 25, 2014
  • 1 reply
  • 583 views

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

This topic has been closed for replies.

1 reply

Jump_Over
Legend
May 26, 2014

Hi,

Check this post if can be helpful...

Re: csharp and Indesign CS5

Did you consider to code it with  javascript?

Jarek

ThinkingThings
Inspiring
May 26, 2014

Hi Jarek,

Looking briefly at the thread that you referenced, I don't see the correlation at all. My best guess is that I am using an improper object reference. As of this moment, I don't think that it is a problem that is resolved by reverting to JS - I think that it is me missing something simple.

Best regards,

TT

Community Expert
May 26, 2014

What kind of object is imageLink? What properties go with that?

Are your destinations visible and available in the GUI?

Uwe