14 Replies Latest reply on Sep 29, 2011 12:22 PM by Econometric

    CS4 fails to Relink images

    Sheldon Zacharias Level 1
      I have a VB script that ran fine with CS2 and CS3, but when I run it with CS4 it fails when I call the Relink method on a Link object. Has anyone experienced any issues with relinking in CS4.
        • 1. Re: CS4 fails to Relink images
          Sheldon Zacharias Level 1
          Has anyone been able to relink images using InDesign CS4 or InDesign CS4 Server?

          I can not get my old CS3 scripts to run. Any input would be appreciated!

          Thanks
          • 2. Re: CS4 fails to Relink images
            Level 1
            Hi Sheldon,

            I've had no problem relinking with InDesign CS4. Typically, I use something like this:

            function myReplaceLink(myLink, myFilePath){
            
            myLink.relink(File(myFilePath));
            myLink.update();
            }


            Where "myLink" is a link and "myFilePath" is a string.

            Thanks,

            Ole
            • 3. Re: CS4 fails to Relink images
              Sheldon Zacharias Level 1
              I have been doing the same thing for years, without a problem, using InDesign or InDesign Server.

              I am just starting to test InDesign Server CS4 and I am finding that it fails everytime I attempt to call the relink method.

              Do you have any experience with InDesign Server CS4?
              • 4. Re: CS4 fails to Relink images
                Level 1
                Hi Sheldon,

                re: "Do you have any experience with InDesign Server CS4?"

                Sure. Can you provide a little bit more code? Are you iterating? Does it work for you in the desktop version of CS4?

                Thanks,

                Ole
                • 5. Re: CS4 fails to Relink images
                  Sheldon Zacharias Level 1
                  I'm using VB.Net, and as I indicated earlier this code works 100% using InDesign Server CS3. Here is a simplified version of the code I am using to relink a image.

                  For X As Integer = 1 To InDesignServerPublication.Document.Links.Count
                  Dim Link As InDesignServer.Link = InDesignServerPublication.Document.Links.Item(X)

                  'I pulled the code that determines the new file name for simplicity
                  Dim strFile as String = "SomeImage"

                  If Not Link.Status = InDesignServer.idLinkStatus.idNormal Then
                  If strFile <> Link.FilePath.ToString Then
                  Link.Relink(strFile)
                  Link.Update()
                  End If
                  End If
                  Next

                  When the code gets to the Link.Relink(strFile) line it errors out with the following error: HRESULT E_FAIL has been returned from a com component.

                  I have not had a chance to try this code with CS4 Desktop, I had to unistall it to get the Server Version installed. I was told by Adobe support that the two can not co-exist on the same machine.
                  • 6. Re: CS4 fails to Relink images
                    Level 1
                    Hi Sheldon,

                    re: " I was told by Adobe support that the two can not co-exist on the same machine."

                    That's incorrect. I wonder where in the world they got that idea.

                    There's always a danger, when iterating through links, that you'll end up pointing at an object reference that is no longer valid. When you relink a link, the original link object is destroyed and a new link object is created. The links collection, therefore, shuffles. Does your problem go away if you iterate in reverse order?

                    Also, it looks to me as if the Relink method now wants a File object (as shown in the JavaScript version above), rather than just a string. Here's an example in VBSCript form.

                    Set myInDesign = CreateObject("InDesign.Application.CS4")
                    
                    Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
                    Set myDocument = myInDesign.Documents.Item(1)
                    For X = myDocument.Links.Count To 1 Step -1
                        Set myLink = myDocument.Links.Item(X)
                        strFile = "C:\test.jpg"
                        Rem If Not myLink.Status = idLinkStatus.idNormal Then
                            If strFile <> myLink.FilePath Then
                                myLink.Relink myFileSystemObject.GetFile(strFile)
                                myLink.Update
                            End If
                        End If
                    Next

                    Thanks,

                    Ole
                    • 7. Re: CS4 fails to Relink images
                      Sheldon Zacharias Level 1
                      Ole,

                      Your a genius! I never thought of checking the input parameter, I just assumed that it would not have changed. I tried using a file object rather than just the file name and it works.

                      I guess my question to Adobe would be why change the parameter type?

                      Either way thank-you very much for the help,
                      Sheldon
                      • 8. Re: CS4 fails to Relink images
                        Level 1
                        Hi Sheldon,

                        Glad it's working!

                        re: "I guess my question to Adobe would be why change the parameter type?"

                        I have no idea, and certainly didn't notice it during development. In general, I develop/test using JavaScript and then port to VBScript and AppleScript, which means that I could easily have missed it (in JavaScript, it always takes a File object).

                        In general, we're supposed to be able to refer to files as either file paths as strings or File objects. Every now and then, someone gets the idea that we need stronger typing, and messes it up.:-)

                        Thanks,

                        Ole
                        • 9. Re: CS4 fails to Relink images
                          Level 1
                          I am unable to relink an EPS file manually indesign CS4. It works using "relink automatically". It is working in CS3 as well.

                          Any suggestions??
                          • 10. Re: CS4 fails to Relink images
                            Level 1

                            After running into this issue also.  Here is some code I came up with for .NET developers.

                             

                             

                             

                            C# code

                             

                            private void Relink(InDesign.Link link, string filename)
                            {

                             

                            object fileSystemObject =

                             

                            Microsoft.VisualBasic.Interaction.CreateObject("Scripting.FileSystemObject", "");

                             

                            Type fileSystemObjectType = Type.GetTypeFromProgID("Scripting.FileSystemObject");

                             

                            object file = fileSystemObjectType.InvokeMember("GetFile", System.Reflection.BindingFlags.InvokeMethod, null, fileSystemObject, new object[] { filename });

                             

                            link.Relink(file);

                             

                            link.Update();
                            }

                             

                            VB.NET code

                             

                            Sub Relink(ByVal Link As InDesign.Link, filename as String)

                             

                            Dim fileSystemObject

                             

                            fileSystemObject = CreateObject("Scripting.FileSystemObject")

                             

                            Link.Relink(fileSystemObject.GetFile(filename))
                            Link.Update()

                             

                            End Sub

                            • 11. Re: CS4 fails to Relink images
                              AdobeScripts Level 3

                              (Olav_Kvern) wrote:

                               

                              [...]

                                      If strFile <> myLink.FilePath Then
                                          myLink.Relink myFileSystemObject.GetFile(strFile)
                                          myLink.Update
                                      End If
                              [...]

                               

                              but why in CS1/CS2/CS3 something like this works fine:

                               

                                myImage.ItemLink.Relink(NewFileName)

                               

                              and myImage is still referencing to image, but in CS4 (with using FileSystemObject) - myImage is Nothing ?

                               

                              robin

                               

                              --

                              www.adobescripts.co.uk

                              • 12. Re: CS4 fails to Relink images
                                Econometric Level 1

                                I am having this problem with CS5. What happens is the script goes through and changes the link paths, but nothing updates for some reason. Once the file is saved and reopened, the new paths are there, but the links are not updated. I tried implementing your version stepping backwards and using the FileSystemObject, and the same exact problem occurred. Please help!!

                                 

                                Dim idLink

                                 

                                For Each idLink In idDoc.Links

                                 

                                idLink.Relink (pathvariable & idLink,Name)

                                idLink.Update

                                 

                                Next idLink

                                • 13. Re: CS4 fails to Relink images
                                  Larry G. Schneider Adobe Community Professional & MVP

                                  Is the comma in line 3 a problem? Should it be idLink.Name

                                  • 14. Re: CS4 fails to Relink images
                                    Econometric Level 1

                                    I was able to finally tweat Ole's method above to work for me. Brilliant work, Ole!