• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Engaged ,
May 25, 2014 May 25, 2014

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

488

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 25, 2014 May 25, 2014

Copy link to clipboard

Copied

Hi,

Check this post if can be helpful...

Re: csharp and Indesign CS5

Did you consider to code it with  javascript?

Jarek

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 26, 2014 May 26, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2014 May 26, 2014

Copy link to clipboard

Copied

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

Are your destinations visible and available in the GUI?

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 26, 2014 May 26, 2014

Copy link to clipboard

Copied

Laubender wrote:

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

Are your destinations visible and available in the GUI?

Uwe

imageLink is a string containing the destination URL. Not sure what you mean by destinations visible and available in the GUI as these are being created by the script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2014 May 26, 2014

Copy link to clipboard

Copied

I wanted to point out and asking, if you made sure a proper Destination for hyperlinks were created by testing this part of your code and looking up the Destination in the GUI.

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 26, 2014 May 26, 2014

Copy link to clipboard

Copied

LATEST

Laubender wrote:

I wanted to point out and asking, if you made sure a proper Destination for hyperlinks were created by testing this part of your code and looking up the Destination in the GUI.

Uwe

I can't test the GUI since the code never gets past the line

Dim myHyperlinkSource = aDoc.HyperlinkPageItemSources.Add(rect)

That said, the URLs work fine if I place them in separate cells. I'm pretty sure that the problem is simply the choice of objects here, but I can't figure it out.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines