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

[CS5][vb.net] Relink problem

Guest
Nov 21, 2010 Nov 21, 2010

Hi,

I'm trying to relink grapics in CS5 with vb.net.  This was easy from CS3 where you simply coded something like   img.ItemLink.Relink("C:\img.jpg").  Now when I do this same code (which worked fine for years), I get the error "{"Cannot create the link resource from the given URI."}".

Has anyone got relink to work in CS5 from any of the .NET languages?  This is a deal-killer for moving my corporation from CS3 to CS5.

Thanks,

Dean.

TOPICS
Scripting
3.3K
Translate
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
New Here ,
Jan 03, 2011 Jan 03, 2011

Hi,

a really ugly workaround is the following.

Suppose myIdApp is a reference to the InDesign application.

Suppose we want to relink the third link in the active document.

Then we could write:

myIdApp.ActiveDocument.Links(3).Relink("C:\Temp\Test.jpg")

However, this doesn't work, as you already noted.

Instead we can write:

Dim myResult as Variant

myResult = myIdApp.DoScript("app.activeDocument.links.item(2).relink(new File(""C:\\Temp\\Test.jpg""))", idJavascript)

This does the relink from the JavaScript engine built into InDesign.

Note the following Points.

* Instead of the index 3 in Links(3), we use the index 2 in links.item(2) since VB uses index base 1 and JavaScript uses index base 0.

* The file object created with new File() is a JavaScript file object. This is accepted by relink() as a valid argument.

I tried using a VB file object obtained from FileSystemObject.GetFile() as an argument in the VB call Links(3).Relink().

But this didn't work.

* All the \ in the file path must be escaped to \\ since the first argument of DoScript() is JavaScript source code.

I tried various other things, but this is the only one that worked for me.

Hope that helps.

Translate
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
New Here ,
Jul 22, 2011 Jul 22, 2011

Hi,

I'm having the same problem when relinking. I'm using the following environment:

1. InDesign CS5 Server

2. C#

And I tried with the following code:

string script = "app.documents[0].links.item(1).relink(new File(" + "\"C:\\Temp\\Test.jpg\"))";

But when I run the application it gives me the following error:

System.Runtime.InteropServices.COMException (0x00007306): Either the file does not exist, you do not have permission, or the file may be in use by another application

But I've checked that the file exists and no one is using the file.

I'm in trouble with this, any help will be highly appreciated.

Best Regards,
-Arafat

Translate
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
New Here ,
Jul 25, 2011 Jul 25, 2011

Finally my problem is fixed 🙂

It was the problem in my script. Now I've written the script this way and worked.

string script = @"app.documents.item(0).links.item(1).relink(new File(""C:\\Temp\\Test.jpg""))";

Thanks,

-Arafat

Translate
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
Explorer ,
Dec 05, 2011 Dec 05, 2011

Just encountered the same bug (?). Is there already a better solution then thementioned  JavaScript workaround?

Translate
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
New Here ,
Dec 27, 2012 Dec 27, 2012

Since I stumbled on this thread with the same error, here's my fix.

InDesign is looking for a URI (file://c/temp/test.jpg")

So, instead of:

myIdApp.ActiveDocument.Links(3).Relink("C:\Temp\Test.jpg")

you could do:

myIdApp.ActiveDocument.Links(3).Relink(new uri("C:\Temp\Test.jpg").tostring)

(or any other way you prefer to use the Uri objects)

Translate
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
Explorer ,
Dec 27, 2012 Dec 27, 2012

Thanks for sharing, I'll try it first thing next year! Just curious: how did you find this out? Is it documented somewhere?

Translate
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
New Here ,
Dec 28, 2012 Dec 28, 2012

Experience? Luck?

There wasn't much to find in the quick google search I used.  The help files I refer (I use a downloaded copy of Jongware's HTML files http://jongware.mit.edu/idcs5js/) just mention String.  The error message "Cannot create the link resource from the given URI." in hindsight was a pretty big hint that I should send it a URI.

Translate
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
Enthusiast ,
Aug 10, 2023 Aug 10, 2023
LATEST

This is a other solution for people:

Dim oFileSystemObject = CreateObject("Scripting.FileSystemObject")
Dim oFile = oFileSystemObject .GetFile(strFilePath)
oLink.Relink(oFile )

Translate
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