1 2 Previous Next 75 Replies Latest reply on Apr 4, 2011 6:11 AM by Kasyan Servetsky

    Re-link lots of images? Indesign CS3

      Hi - I posted this in the indesign forum and it was suggested to look here. I've had a quick look for a solution but thought I'd post aswell.

      "Because I've resaved a load of jpegs to psds the links are now broken.

      Is it possible to relink them all without doing each one manually?

      The update link option is greyed out. All the psds are in the same folder. "

      Thanks again
        • 1. Re: Re-link lots of images? Indesign CS3
          Level 1
          for MAC or for PC ??
          (I don't see your post on adobe.indesign.windows forum)

          robin

          --
          www.adobescripts.com
          • 2. Re: Re-link lots of images? Indesign CS3
            Level 1
            Hi

            For MAC.

            Thanks
            • 3. Re: Re-link lots of images? Indesign CS3
              Kasyan Servetsky Level 5
              Hi jamesho,
              I haven't tested it, but think it's should be something like this:
              //-------------------------------
              var myImages = app.activeDocument.allGraphics;
              
              for (i = myImages.length-1; i >= 0 ; i--) {
                 var myImage = myImages[i].itemLink;
                 var myNewName = myImage.filePath.replace(/\.jpg$/i, "") + ".psd";
                 var myNewLink =  new File (myNewName);
                    if (myNewLink.exists) {
                       myImage.relink (myNewLink);
                       myImage.update();
                    }
              }

              //-------------------------------
              I assume JPG and PSD files are in the same folder.
              Kasyan
              • 4. Re: Re-link lots of images? Indesign CS3
                Level 1
                Hi Kasyan,

                Thanks for your reply. To be honest I don't know anything about scripts and am not sure what to do with the info you've posted. Can you help?

                The other thing is I've trashed all the JPG thinking I didn't need them anymore.

                James
                • 5. Re: Re-link lots of images? Indesign CS3
                  Kasyan Servetsky Level 5
                  1 Copy the code I posted
                  2. Start up ExtendScript Toolkit 2 (Applications > Utilities > Adobe Utilities > ExtendScript Toolkit 2 folder)
                  3. Create a new file
                  4. Paste the code
                  5. Save the Script into Applications > Adobe InDesign CS3 > Scripts > Scripts Panel folder, or alternatively into your home directory > Library > Preferences > Adobe InDesign > Version 5.0 > Scripts > Scripts Panel folder

                  Your PSD files should be in the same folder (have the same path) as where the JPG files used to be.
                  Open your document and double click the script in the Scripts Panel (Window > Automation > Scripts.

                  I can send you the script, if you e-mail me at kasyan@business.ua

                  Kasyan
                  • 6. Re: Re-link lots of images? Indesign CS3
                    (dej) Level 1
                    Can you tell me if this would work or could be adjusted to work if the file names were changed rather than just the suffix.

                    I've placed an Illustrator image in IDCS3 many times but since then I've renamed the file and now ID is looking for the original. The only way I could update them all was to relink each one individually. Is there a way of relinking them all collectively?

                    I'm sure the above script would do the job but it may need some expert tinkering before hand.

                    David
                    • 7. Re: Re-link lots of images? Indesign CS3
                      Kasyan Servetsky Level 5
                      >Is there a way of relinking them all collectively?

                      After you pressed Relink button or chose Relink menu command in Links Panel, you should set Relink All Instances of “YourFileName.ai” check box.

                      Kasyan
                      • 8. Re: Re-link lots of images? Indesign CS3
                        how could this be modified so that...
                        1. instead of a changed filename it looks for the same name in a NEW folder.
                        2. possibly ignore the extensions and link to a file with the same base filename.

                        I had one that worked great in CS2 but can't find it.
                        • 9. Re: Re-link lots of images? Indesign CS3
                          Kasyan Servetsky Level 5
                          Hi Kevin,
                          I made this script in a rough-and-ready fashion – don’t have time to test it. Hope it does what you want. If not, let me know.
                          myNewFolder variable is set to “NewLinks” folder is in the same folder where your active InDesign document has been saved, but you can type any path you need, or I can make a dialog to choose a folder with new links.

                          Kasyan
                          //---------------------------------------------------
                          var myDoc = app.activeDocument;
                          
                          // NewLinks folder is in the same folder where your active InDesign document has been saved
                          var myNewFolder = myDoc.filePath + "/NewLinks/";
                          // List  all possible file extension in this array
                          var myExtentions = [".psd", ".tif", ".jpg", ".eps", ".pdf"];
                          var myImages = app.activeDocument.allGraphics;
                          for (i = myImages.length-1; i >= 0 ; i--) {
                             var myImage = myImages[i].itemLink;
                             var myOldPath = myImage.filePath;
                             var myNewPath = myNewFolder + myImage.name;
                                if (myOldPath != myNewPath) {
                                   var myResult = myRelink(myNewPath);
                                   if (myResult == false) {
                                      for (var k = 0; k < myExtentions.length; k++)  {
                                         try {
                                            myNewPath = myNewPath.slice(0,-4) + myExtentions[k];
                                            myRelink(myNewPath);
                                         }
                                         catch (myError){}
                                      }
                                   }
                                }


                          function myRelink(myNewPath) {
                             var myNewLink =  new File (myNewPath);
                                if (myNewLink.exists) {
                                   myImage.relink (myNewLink);
                                   myImage.update();
                                   return true;
                                }
                             return false;
                          }
                          • 10. Re: Re-link lots of images? Indesign CS3
                            Kasyan Servetsky Level 5
                            Here is a new and improved version of the above script. May be it will come in handy to somebody.
                            //-------------------------------------------------
                            if(app.documents.length != 0){
                            
                              var myFolder = Folder.selectDialog ("Choose a folder with new links");
                               if(myFolder != null){
                               var myCounter = 0;
                               main();
                               }
                            }
                            else {
                               alert("Please open a document and try again.");
                            }
                            function main(){
                               var myDoc = app.activeDocument;
                               var myNewFolder = myFolder.fsName + "/";
                               // List  all possible file extension in this array
                               var myExtentions = [".psd", ".tif", ".jpg", ".eps", ".pdf", ".indd"];
                               var myImages = app.activeDocument.allGraphics;
                               for (i = myImages.length-1; i >= 0 ; i--) {
                                  var myImage = myImages[i].itemLink;
                                  var myOldPath = myImage.filePath;
                                  var myNewPath = myNewFolder + myImage.name;    
                                  if (Folder.fs == "Macintosh") {
                                     myOldPath = "/" + myOldPath.replace(/:/g, "/");
                                  }
                                  else if  (Folder.fs == "Windows") {
                                     myNewPath = myNewPath.replace(/\//g, "\\");
                                  }
                                     if (myOldPath != myNewPath) {
                                        var myResult = myRelink(myNewPath, myImage);
                                        if (myResult == false) {
                                           for (var k = 0; k < myExtentions.length; k++)  {
                                              try {
                                                 myNewPath = myNewPath.slice(0,-4) + myExtentions[k];
                                                 myRelink(myNewPath, myImage);
                                              }
                                              catch (myError){}
                                           }
                                        }
                                     }
                               } 
                            if (myCounter > 0) {
                               alert(myCounter + " files has been relinked.");
                               }
                            else {
                               alert("Nothing has been relinked.");
                               }
                            }
                            function myRelink(myNewPath, myImage) {
                               var myNewLink =  new File (myNewPath);
                                  if (myNewLink.exists) {
                                     myImage.relink (myNewLink);
                                     myImage.update();
                                     myCounter++;
                                     return true;
                                  }
                               return false;
                            }
                            • 11. Re: Re-link lots of images? Indesign CS3
                              Kasyan!!

                              Dude you saved my ***!! I had 1200 PDFs and EPS all needing relink location changes!!!

                              Thank you!
                              Simon
                              • 12. Re: Re-link lots of images? Indesign CS3
                                DTPAntoin
                                Hi,

                                Is there any way this script could be edited to look in subfolders of the folder you choose from the dialogue box? This would solve a problem that has been bugging me for a long time.

                                Antóin.
                                • 13. Re: Re-link lots of images? Indesign CS3
                                  Kasyan Servetsky Level 5
                                  Hi Antóin,

                                  I'll try to do it a little bit later today.

                                  Kasyan
                                  • 14. Re: Re-link lots of images? Indesign CS3
                                    DTPAntoin Level 1
                                    Fantastic.

                                    Thanks,

                                    Antóin.
                                    • 15. Re: Re-link lots of images? Indesign CS3
                                      Kasyan Servetsky Level 5
                                      Antóin,

                                      You can download the script from here:
                                      http://www.businessweekly.h.com.ua/relink.html
                                      or just copy and paste from this post.

                                      I hope it will work for you. If you find any bugs let me know.

                                      Kasyan
                                      //---------------------------------------------
                                      This script relinks old links with new ones in a folder you choose, including subfolders.
                                      At first, it looks for the new link that has the same name as the old one in the selected folder and if it's found, relinks it.
                                      If the link with the exact name is not found, the sript tries to find a file with the same base name but a different extension (".psd", ".tif", ".jpg", ".eps", ".pdf", ".indd").
                                      If the script doesn't find the new link in the chosen folder, it searches it in all subfolders.
                                      //---------------------------------------------

                                      if(app.documents.length != 0){
                                         var myDoc = app.activeDocument;
                                         var myFolder = Folder.selectDialog ("Choose a folder with new links");
                                         if(myFolder != null){
                                            var myCounter = 0;
                                            var mySubFolders = new Array;
                                            getSubFolders(myFolder);
                                            var myNewFolder = myFolder.absoluteURI + "/";
                                            main(myNewFolder);
                                            if (mySubFolders.length > 0) {
                                               for (var s = 0; s < mySubFolders.length; s++)  {
                                                  myNewFolder = mySubFolders[s] + "/";
                                                  main(myNewFolder);
                                               }
                                            }
                                            if (myCounter == 1) {
                                               alert("One file has been relinked.");
                                            }
                                            else if  (myCounter > 1) {
                                               alert(myCounter + " files have been relinked.");
                                            }
                                            else {
                                               alert("Nothing has been relinked.");
                                            }
                                         }
                                      }
                                      else {
                                         alert("Please open a document and try again.");
                                      }
                                      function main(myNewFolder){
                                         // List all possible file extension in this array
                                         var myExtentions = [".psd", ".tif", ".jpg", ".eps", ".pdf", ".indd"];
                                         var myImages = app.activeDocument.allGraphics;
                                         var myCurrFolder = Folder (myNewFolder);
                                         var myCurrFolderName = "Folder  " + myCurrFolder.displayName;
                                         var stop = myImages.length;
                                         var w = new Window ( 'window', myCurrFolderName );
                                         var pb = w.add ('progressbar', [12, 12, 350, 24], 0, stop);
                                         var txt = w.add('statictext');
                                         txt.bounds = [0, 0, 340, 20];
                                         txt.alignment = "left";
                                         w.show();
                                         var a = 1;
                                         for (i = myImages.length-1; i >= 0 ; i--) {
                                            var b = (myImages.length - myImages.length) + a;
                                            pb.value = b;
                                            a++;
                                            var myText = String("Relinking file  " + myImages[i].itemLink.name);
                                            txt.text = myText;
                                            var myImage = myImages[i].itemLink;
                                            var myImageFile = new File (myImage.filePath);
                                            var myOldPath = myImageFile.toString();
                                            var myNewPath = myNewFolder + myImage.name;
                                            if (myOldPath != myNewPath) {
                                               var myResult = myRelink(myNewPath, myImage);
                                               if (myResult == false) {
                                                  for (var k = 0; k < myExtentions.length; k++)  {
                                                     try {
                                                        myNewPath = myNewPath.slice(0,-4) + myExtentions[k];
                                                        myRelink(myNewPath, myImage);
                                                     }
                                                     catch (myError){}
                                                  }
                                               }
                                            }
                                         }
                                         w.close();
                                      }
                                      function myRelink(myNewPath, myImage) {
                                         var myNewLink =  new File (myNewPath);
                                            if (myNewLink.exists) {
                                               myImage.relink (myNewLink);
                                               myImage.update();
                                               myCounter++;
                                               return true;
                                            }
                                         return false;
                                      }
                                      function getSubFolders(theFolder) {
                                         var myFileList = theFolder.getFiles();
                                         for (var i = 0; i < myFileList.length; i++) {
                                            var myFile = myFileList[i];
                                            if (myFile instanceof Folder){
                                               mySubFolders.push(myFile.absoluteURI);
                                               getSubFolders(myFile);
                                            }
                                         }
                                         return mySubFolders;
                                      }
                                      • 16. Re: Re-link lots of images? Indesign CS3
                                        DTPAntoin Level 1
                                        Hi Kasyan,

                                        Thanks so much for that. It takes a while to work but it works a treat. Saves me a whole lot of time relinking images for documents as I save all my images in one folder and have subfolders within that. It was so annoying having to search through linking images everytime.

                                        Thanks again,

                                        Antóin.
                                        • 17. Re: Re-link lots of images? Indesign CS3
                                          Kasyan Servetsky Level 5
                                          Hi all,

                                          Today I received an e-mail from a guy who had a problem with the script I had posted. The problem was that he had CS2 but the script was written for CS3. I removed the progress bar from the script so now it works in CS2, and posted both versions here:
                                          http://www.businessweekly.h.com.ua/relink.html
                                          (In case somebody else is interested).

                                          Kasyan
                                          • 18. Re: Re-link lots of images? Indesign CS3
                                            myDwayneSmith Level 1
                                            Hi Kasyan,

                                            I am constantly amazed at how generous you and the other scripters on this forum are...

                                            So many threads go somethiing like this:
                                            Poster1: "I need to do something but I have no idea how to...and I haven't really tried to learn..."
                                            Scripter: "Here's a script that should do what you need"
                                            Poster1: "Wow, that's great. But can you also make it do....."
                                            Scripter: "No worries, here's a revised version"
                                            Poster2: "Could you also make it do...."
                                            Scripter: "Yep, no worries, here's a more complicated version."

                                            You contributors are all wonderfully brilliant people. Thanks so much,
                                            d.
                                            • 19. Re: Re-link lots of images? Indesign CS3
                                              This is so helpful! Is there any way that this script could be applied to an entire book rather than just one document?

                                              Thanks so much!
                                              Elizabeth
                                              • 20. Re: Re-link lots of images? Indesign CS3
                                                Kasyan Servetsky Level 5
                                                Hi Dwayne Smith and Elizabeth,

                                                Its so nice to read such kind words. For me, its important to have such a feedback, because if I know that people use my script I have a strong incentive to improve it. Im working on a new version: my goal is to make the script stop searching for the further folders, if the image has been successfully linked. The idea was given by Bharathi Raja on this thread http://www.adobeforums.com/webx/.59b5c193/11

                                                >Is there any way that this script could be applied to an entire book rather than just one document?

                                                Im sure its possible; Ill give it a try when I have a little spare time. And right now I have a question for you: the script needs to know which book to work with. Do you usually keep one or several book(s) open in InDesign? In the first case, its easier to do; in the second Ill have to write a dialog box for the user to choose a book.

                                                Kasyan
                                                • 21. Re: Re-link lots of images? Indesign CS3
                                                  Kasyan, you totally rock! I used your script and it worked great. Thank you for saving my wrists from carpal tunnel!!
                                                  • 22. Re: Re-link lots of images? Indesign CS3
                                                    Kasyan Servetsky Level 5
                                                    Hi all,

                                                    Ive posted a new, totally remade and much better (I hope) version of the script for updating path names in links.
                                                    http://www.businessweekly.h.com.ua/relink.html
                                                    The previous version 8.8 has a problem with processing subfolders, as pointed out here http://www.adobeforums.com/webx?128@@.59b5c193 (post 11) by Bharathi Raja.
                                                    Now, if the script finds and successfully relinks a link, it stops searching and replacing this link in subsequent subfolders. It now also works both in InDesign CS2 and CS3.

                                                    Id like to make a little public opinion poll:
                                                    Does anybody need the script to work with other file formats (e.g. linked InCopy files)?
                                                    Im thinking of adding a window at start, for user to have a choice to select where script should work e.g. Active document/All open documents/Select a book (from listbox). What do you think about it?
                                                    Now concerning embedded links: at present, if the script finds a link with same base name it unembeds and relinks it to this link. Does anybody need more control for embedded links? (e.g. a checkbox to relink/dont relink embedded links)

                                                    Kasyan
                                                    • 23. Re: Re-link lots of images? Indesign CS3
                                                      Kasyan Servetsky Level 5
                                                      I found a bug in the script that I posted yesterday: not all file extensions were processed by the script properly. Now Ive corrected the mistake and posted a new version 10.1.
                                                      http://www.businessweekly.h.com.ua/relink.html
                                                      • 24. Re: Re-link lots of images? Indesign CS3
                                                        c.pfaffenbichler Level 8
                                                        Great Script.
                                                        I have to concur with Dwayne, some of the posters in the Scripting-fora are remarkably generous with their expertise; thanks, Kasyan.

                                                        One peculiarity: at least on my station I get »One file has been relinked.« even if a lot more files have actually been relinked.

                                                        Regarding Your poll:
                                                         The file-formats You implemented so far suffice for my needs.
                                                         The opportunity to apply to all open documents seems nice though not essential.
                                                         No opinion  as I usually dont embed images in Indesign-documents anyway.
                                                        One feature I myself (due to the way we organize images around the company I work at) would find useful would be the adding/recognition of additional »suffixes«; depending on print-conditions we often have numerous versions of an image that have been separated utilizing different profiles which are signified by an added »_coa«, »_web« etc. at the end of the filename. But Im not sure if that way of handling images is widespread enough to merit consideration.
                                                        • 25. Re: Re-link lots of images? Indesign CS3
                                                          Kasyan Servetsky Level 5
                                                          Hi Christoph,

                                                          Thank you for the response. I like your idea about suffixes; maybe Ill add this feature to the script some day.

                                                          >One peculiarity: at least on my station I get »One file has been relinked.« even if a lot more files have actually been relinked.

                                                          Ill recheck this again. Do you have the latest version of the script 10.1?

                                                          Kasyan
                                                          • 26. Re: Re-link lots of images? Indesign CS3
                                                            c.pfaffenbichler Level 8
                                                            Yes, I have just downloaded »Update path names in links 10-1.jsx« today.
                                                            Its no biggie anway, but You seem to be a perfectionist, so I thought Id mention it.
                                                            • 27. Re: Re-link lots of images? Indesign CS3
                                                              Hi Kasyan

                                                              I've learned so much from here - thank you for your time and effort you have put into helping everyone

                                                              I had been struggling with the DOM within InDesign - i had managed to write a .jsx to iterate through every text box of every page and gather all the text into a single variable (for me this was an improvement on the export text). Then i saw this page and your posts opened my eyes to the automation of image tasks

                                                              One thing i cannot work out though (i cant find anywhere) - is it possible to rename the images on the hard disk themselves via the script - rather than just the links?

                                                              I don't need any lengthy code - just a snippit of code that would show me how to rename the physical images themselves

                                                              For example:
                                                              An InDesign document may have 3 pages and on each page may exist a few pics. These could all have obscure names, but we require the script to iterate through each page, create a tidy, unique picture identifier PAGE_001_image01.tif, PAGE_001_imageB02.tif, PAGE_002_image01.tif, PAGE_002_image02.tif, PAGE_002_image03.tif. In order to do this i would need to be able to update the link within InDesign (very easy, thanks to you) and the files themselves

                                                              Sorry for the lengthy explanation

                                                              Regards
                                                              Duncan
                                                              • 28. Re: Re-link lots of images? Indesign CS3
                                                                Kasyan Servetsky Level 5
                                                                Hi Duncan,

                                                                Surely it’s possible. I just reinstalled the system on my home computer and haven’t installed Indesing yet, so I wrote this code in Incopy, but it should work in Indesing too. I’ll test it later at work today.

                                                                Kasyan
                                                                ------------------------------------------


                                                                var myDoc = app.activeDocument;
                                                                var myImages = myDoc.allGraphics;
                                                                var myPages = myDoc.pages;
                                                                // If the document doesn't contain any images, give alert and exit
                                                                if (myImages.length == 0) {
                                                                   alert("This document doesn't contain any images.", "Script will be terminated");
                                                                   exit(); 
                                                                }

                                                                for (var p = 0; p < myPages.length; p++) {
                                                                   var myPageNumber = pagenum(myPages[p].name);
                                                                   for (i = myImages.length-1; i >= 0 ; i--) {
                                                                      var myLink = myImages[i].itemLink;
                                                                      var myImageCounter = i + 1;
                                                                      var myImageNumber = pagenum(myImageCounter);
                                                                      var myOldLinkName = myLink.name;
                                                                      // I assume that all extensions consist of 3 characters
                                                                      var myExtension = myOldLinkName.substr(-4, 4);
                                                                      var myNewLinkName = "PAGE_" + myPageNumber  + "_image" + myImageNumber + myExtension;
                                                                      var myOldImageFile = new File (myLink.filePath);
                                                                      var myOldPath = myOldImageFile.toString();
                                                                      var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);
                                                                      myOldImageFile.rename(myNewPath);
                                                                      myLink.relink (myOldImageFile);
                                                                      myLink.update();
                                                                   }
                                                                }

                                                                function pagenum(myNumber){
                                                                   if (myNumber >= 1 && myNumber <= 9)
                                                                   {
                                                                   x =  "0" + "0" + myNumber;
                                                                   }
                                                                   else if (myNumber >= 10 && myNumber <= 99)
                                                                   {
                                                                   x = "0" + myNumber;
                                                                   }
                                                                   else if (myNumber >= 100 && myNumber <= 999)
                                                                   {
                                                                   x = myNumber;
                                                                   }
                                                                return x
                                                                }
                                                                • 29. Re: Re-link lots of images? Indesign CS3
                                                                  Kasyan Servetsky Level 5
                                                                  Oops! I just tested my previous script and found a mistake, dont use it. Sorry, here is a new version. It works on PC in CS3, but on Mac doesnt I dont know why yet.
                                                                  //---------------------------------
                                                                  var myDoc = app.activeDocument;
                                                                  
                                                                  var myPages = myDoc.pages;

                                                                  for (var p = 0; p < myPages.length; p++) {
                                                                     var myPageNumber = pagenum(myPages[p].name);
                                                                     var myImages = myPages[p].allGraphics;
                                                                     for (i = myImages.length-1; i >= 0 ; i--) {
                                                                        var myLink = myImages[i].itemLink;
                                                                        var myImageCounter = i + 1;
                                                                        var myImageNumber = pagenum(myImageCounter);
                                                                        var myOldLinkName = myLink.name;
                                                                        // I assume that all extensions consist of 3 characters
                                                                        var myExtension = myOldLinkName.substr(-4, 4);
                                                                        var myNewLinkName = "PAGE_" + myPageNumber  + "_image" + myImageNumber + myExtension;
                                                                        var myOldImageFile = new File (myLink.filePath);
                                                                        var myOldPath = myOldImageFile.toString();
                                                                        var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);
                                                                        myOldImageFile.rename(myNewPath);
                                                                        myLink.relink (myOldImageFile);
                                                                        myLink.update();
                                                                     }
                                                                  }

                                                                  function pagenum(myNumber){
                                                                     if (myNumber >= 1 && myNumber <= 9)
                                                                     {
                                                                     x =  "0" + "0" + myNumber;
                                                                     }
                                                                     else if (myNumber >= 10 && myNumber <= 99)
                                                                     {
                                                                     x = "0" + myNumber;
                                                                     }
                                                                     else if (myNumber >= 100 && myNumber <= 999)
                                                                     {
                                                                     x = myNumber;
                                                                     }
                                                                  return x
                                                                  }
                                                                  • 30. Re: Re-link lots of images? Indesign CS3
                                                                    Kasyan Servetsky Level 5
                                                                    Aha! Now I see why it doesnt work on Mac: instead of
                                                                    myOldImageFile.rename(myNewPath);
                                                                    it should be
                                                                    myOldImageFile.rename(myNewLinkName);
                                                                    because newName should be file name, with no path information.
                                                                    However it is strange that it worked on PC.
                                                                    Here a new version again:
                                                                    //-----------------------------------------
                                                                    var myDoc = app.activeDocument;
                                                                    
                                                                    var myPages = myDoc.pages;

                                                                    for (var p = 0; p < myPages.length; p++) {
                                                                       var myPageNumber = pagenum(myPages[p].name);
                                                                       var myImages = myPages[p].allGraphics;
                                                                       for (i = myImages.length-1; i >= 0 ; i--) {
                                                                          var myLink = myImages[i].itemLink;
                                                                          var myImageCounter = i + 1;
                                                                          var myImageNumber = pagenum(myImageCounter);
                                                                          var myOldLinkName = myLink.name;
                                                                          // I assume that all extensions consist of 3 characters
                                                                          var myExtension = myOldLinkName.substr(-4, 4);
                                                                          var myNewLinkName = "PAGE_" + myPageNumber  + "_image" + myImageNumber + myExtension;
                                                                          var myOldImageFile = new File (myLink.filePath);
                                                                          var myOldPath = myOldImageFile.toString();
                                                                          var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);
                                                                          myOldImageFile.rename(myNewLinkName);
                                                                          myLink.relink (myOldImageFile);
                                                                          myLink.update();
                                                                       }
                                                                    }

                                                                    function pagenum(myNumber){
                                                                       if (myNumber >= 1 && myNumber <= 9)
                                                                       {
                                                                       x =  "0" + "0" + myNumber;
                                                                       }
                                                                       else if (myNumber >= 10 && myNumber <= 99)
                                                                       {
                                                                       x = "0" + myNumber;
                                                                       }
                                                                       else if (myNumber >= 100 && myNumber <= 999)
                                                                       {
                                                                       x = myNumber;
                                                                       }
                                                                    return x
                                                                    }
                                                                    • 31. Re: Re-link lots of images? Indesign CS3
                                                                      Level 1
                                                                      Hi Kasyan

                                                                      Thank you so much - i am so impressed

                                                                      I have been dreaming of being able to do this for quite some time, and you have single-handedly made it possible

                                                                      I do use a Mac and was baffled why the previous script didn't work - the script looked like it should work (i was playing around for some time trying to work out why not, but i was just not knowledgeable enough to make it work)

                                                                      However, this revised script is PERFECT! My head is spinning with the possibilities of this scripting. I have been programming in Perl for approx. 10 years and am only just getting into OO methodology. This then opened up my understanding of AS 3 within Flash. This made C more understandable. And Java. And now, thanks to you, i am getting to grips with scripting Adobe's applications. I have already managed to tackle many labourious tasks with scripting techniques, rather than manually.

                                                                      I get the feeling that so many people are missing out on some serious power offered by scripting the applications; i don't know a single person who exploits this - and probably are ill aware of what they are missing out on.

                                                                      I assure you that this is incredibly interesting to me, and i am going to study your script in depth until i know it back-to-front. This is the only way i feel comfortable.

                                                                      Thanks again Kasyan - you are very kind

                                                                      Regards
                                                                      Duncan
                                                                      • 32. Re: Re-link lots of images? Indesign CS3
                                                                        Level 1
                                                                        Wonderful! Thank you, thank you!
                                                                        • 33. Re: Re-link lots of images? Indesign CS3
                                                                          Level 1
                                                                          Hi Kasyan

                                                                          I have been playing around with this for some time now - although i am having problems with any image used more than once

                                                                          I am banging my head against a wall here - once the update is done on any first instance of an image, then subsequent ones fail [ i guess due to the fact that the link is now broken ]

                                                                          I have incorporated a check for an active / broken link, allowing different actions to be performed, and an Object to remember the revised link of pre-processed files, and a regular expression steal the characters after the last full stop [ in case the file extensions are 4 characters, for example ]

                                                                          I would be very grateful if you could help me with this

                                                                          Thank you!

                                                                          var myDoc = app.activeDocument;
                                                                          var myImages = myDoc.allGraphics;
                                                                          var seen = Object;
                                                                          var messageCounter = 0;

                                                                          for (var i = myImages.length-1; i >= 0; i--) {
                                                                          var myOldLink = myImages[i].itemLink;
                                                                          var myOldLinkName = myOldLink.name;
                                                                          if (seen[myOldLinkName]) {
                                                                          //alert("SEEN\n" + myOldLinkName);
                                                                          } else {
                                                                          //alert("FIRST SEEN\n" + myOldLinkName);
                                                                          seen[myOldLinkName] = 1;
                                                                          }
                                                                          }

                                                                          var myPages = myDoc.pages;
                                                                          for (var p = 0; p < myPages.length; p++) {
                                                                          var myPageNumber = zeros3(myPages[p].name);
                                                                          var myImageNumber;
                                                                          var imagesPerPageCounter = 1;
                                                                          //alert("PAGE " + myPageNum);

                                                                          myImages = myPages[p].allGraphics;
                                                                          for (i = myImages.length-1; i >= 0; i--) {
                                                                          myOldLink = myImages[i].itemLink; // [ object ]
                                                                          myOldLinkName = myOldLink.name;
                                                                          myImageNumber = zeros2(imagesPerPageCounter);
                                                                          var myFileExtensionRegEx = /\.[^.]+$/g;
                                                                          var imageExtension = myOldLinkName.match(myFileExtensionRegEx);
                                                                          var whereHasTheLinkGone = Object;
                                                                          var whatWasTheLinkName = Object;

                                                                          if (myOldLink.status == 1852797549) { // *** LINK O.K. ***

                                                                          myNewLinkName = 'PREPENDED_P' + myPageNumber + "_image" + myImageNumber + imageExtension;

                                                                          var myOldImageFile = new File(myOldLink.filePath);
                                                                          var myOldPath = myOldImageFile.toString();
                                                                          var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);

                                                                          myOldImageFile.rename(myNewLinkName);
                                                                          myOldLink.relink(myOldImageFile);
                                                                          myOldLink.update();

                                                                          whereHasTheLinkGone[myOldLinkName] = myOldImageFile;
                                                                          whatWasTheLinkName[myOldLinkName] = myNewLinkName;

                                                                          feedback("LINK O.K. : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);

                                                                          imagesPerPageCounter++;

                                                                          } else { // LINK BROKEN

                                                                          // ********** HOW CAN I LINK TO THE RENAMED IMAGE HERE ? **********

                                                                          feedback("LINK MISSING : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);

                                                                          }
                                                                          }
                                                                          }

                                                                          function zeros3(myNumber) {
                                                                          if (myNumber >= 1 && myNumber <= 9) {
                                                                          x = "0" + "0" + myNumber;
                                                                          }
                                                                          else if (myNumber >= 10 && myNumber <= 99) {
                                                                          x = "0" + myNumber;
                                                                          }
                                                                          else if (myNumber >= 100 && myNumber <= 999) {
                                                                          x = myNumber;
                                                                          }
                                                                          return x;
                                                                          }

                                                                          function zeros2(myNumber) {
                                                                          if (myNumber >= 1 && myNumber <= 9) {
                                                                          x = "0" + myNumber;
                                                                          }
                                                                          else if (myNumber >= 10 && myNumber <= 99) {
                                                                          x = myNumber;
                                                                          }
                                                                          return x;
                                                                          }

                                                                          function feedback(message) {
                                                                          if (messageCounter++ < 10) {
                                                                          alert(message);
                                                                          }
                                                                          }

                                                                          Duncan
                                                                          • 34. Re: Re-link lots of images? Indesign CS3
                                                                            Level 1
                                                                            Hi Kasyan

                                                                            I have been playing around with this for some time now - although i am having problems with any image used more than once

                                                                            I am banging my head against a wall here - once the update is done on any first instance of an image, then subsequent ones fail [ i guess due to the fact that the link is now broken ]

                                                                            I have incorporated a check for an active / broken link, allowing different actions to be performed, and an Object to remember the revised link of pre-processed files, and a regular expression steal the characters after the last full stop [ in case the file extensions are 4 characters, for example ]

                                                                            I would be very grateful if you could help me with this

                                                                            Thank you!


                                                                            var myDoc = app.activeDocument;
                                                                            var myImages = myDoc.allGraphics;
                                                                            var seen = Object;
                                                                            var messageCounter = 0;

                                                                            for (var i = myImages.length-1; i >= 0; i--) {
                                                                            var myOldLink = myImages[i].itemLink;
                                                                            var myOldLinkName = myOldLink.name;
                                                                            if (seen[myOldLinkName]) {
                                                                              //alert("SEEN\n" + myOldLinkName);
                                                                            } else {
                                                                              //alert("FIRST SEEN\n" + myOldLinkName);
                                                                              seen[myOldLinkName] = 1;
                                                                            }
                                                                            }

                                                                            var myPages = myDoc.pages;
                                                                            for (var p = 0; p < myPages.length; p++) {
                                                                            var myPageNumber = zeros3(myPages[p].name);
                                                                            var myImageNumber;
                                                                            var imagesPerPageCounter = 1;
                                                                            //alert("PAGE " + myPageNum);

                                                                            myImages = myPages[p].allGraphics;
                                                                            for (i = myImages.length-1; i >= 0; i--) {
                                                                              myOldLink = myImages[i].itemLink; // [ object ]
                                                                              myOldLinkName = myOldLink.name;
                                                                              myImageNumber = zeros2(imagesPerPageCounter);
                                                                              var myFileExtensionRegEx = /\.[^.]+$/g;
                                                                              var imageExtension = myOldLinkName.match(myFileExtensionRegEx);
                                                                              var whereHasTheLinkGone = Object;
                                                                              var whatWasTheLinkName = Object;

                                                                              if (myOldLink.status == 1852797549) { // *** LINK O.K. ***
                                                                             
                                                                               myNewLinkName = 'PREPENDED_P' + myPageNumber + "_image" + myImageNumber + imageExtension;

                                                                               var myOldImageFile = new File(myOldLink.filePath);
                                                                               var myOldPath = myOldImageFile.toString();
                                                                               var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);
                                                                                
                                                                               myOldImageFile.rename(myNewLinkName);
                                                                               myOldLink.relink(myOldImageFile);
                                                                               myOldLink.update();
                                                                             
                                                                               whereHasTheLinkGone[myOldLinkName] = myOldImageFile;
                                                                               whatWasTheLinkName[myOldLinkName] = myNewLinkName;
                                                                             
                                                                               feedback("LINK O.K. : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);
                                                                             
                                                                               imagesPerPageCounter++;

                                                                              } else { // LINK BROKEN

                                                                               // ********** HOW CAN I LINK TO THE RENAMED IMAGE HERE ? **********
                                                                             
                                                                               feedback("LINK MISSING : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);

                                                                              }
                                                                            }
                                                                            }

                                                                            function zeros3(myNumber) {
                                                                            if (myNumber >= 1 && myNumber <= 9) {
                                                                              x =  "0" + "0" + myNumber;
                                                                            }
                                                                            else if (myNumber >= 10 && myNumber <= 99) {
                                                                              x = "0" + myNumber;
                                                                            }
                                                                            else if (myNumber >= 100 && myNumber <= 999) {
                                                                              x = myNumber;
                                                                            }
                                                                            return x;
                                                                            }

                                                                            function zeros2(myNumber) {
                                                                            if (myNumber >= 1 && myNumber <= 9) {
                                                                              x =  "0" + myNumber;
                                                                            }
                                                                            else if (myNumber >= 10 && myNumber <= 99) {
                                                                              x = myNumber;
                                                                            }
                                                                            return x;
                                                                            }

                                                                            function feedback(message) {
                                                                            if (messageCounter++ < 10) {
                                                                              alert(message);
                                                                            }
                                                                            }



                                                                            Duncan
                                                                            • 35. Re: Re-link lots of images? Indesign CS3
                                                                              Level 1
                                                                              Hi Kasyan

                                                                              I have been playing around with this for some time now - although i am having problems with any image used more than once

                                                                              I am banging my head against a wall here - once the update is done on any first instance of an image, then subsequent ones fail [ i guess due to the fact that the link is now broken ]

                                                                              I have incorporated a check for an active / broken link, allowing different actions to be performed, and an Object to remember the revised link of pre-processed files, and a regular expression steal the characters after the last full stop [ in case the file extensions are 4 characters, for example ]

                                                                              I would be very grateful if you could help me with this

                                                                              Thank you!

                                                                              var myDoc = app.activeDocument;
                                                                              
                                                                              var myImages = myDoc.allGraphics;
                                                                              var seen = Object;
                                                                              var messageCounter = 0;

                                                                              for (var i = myImages.length-1; i >= 0; i--) {
                                                                                var myOldLink = myImages[i].itemLink;
                                                                                var myOldLinkName = myOldLink.name;
                                                                                if (seen[myOldLinkName]) {
                                                                                  //alert("SEEN\n" + myOldLinkName);
                                                                                } else {
                                                                                  //alert("FIRST SEEN\n" + myOldLinkName);
                                                                                  seen[myOldLinkName] = 1;
                                                                                }
                                                                              }

                                                                              var myPages = myDoc.pages;
                                                                              for (var p = 0; p < myPages.length; p++) {
                                                                                var myPageNumber = zeros3(myPages[p].name);
                                                                                var myImageNumber;
                                                                                var imagesPerPageCounter = 1;
                                                                                //alert("PAGE " + myPageNum);

                                                                                myImages = myPages[p].allGraphics;
                                                                                for (i = myImages.length-1; i >= 0; i--) {
                                                                                  myOldLink = myImages[i].itemLink; // [ object ]
                                                                                  myOldLinkName = myOldLink.name;
                                                                                  myImageNumber = zeros2(imagesPerPageCounter);
                                                                                  var myFileExtensionRegEx = /\.[^.]+$/g;
                                                                                  var imageExtension = myOldLinkName.match(myFileExtensionRegEx);
                                                                                  var whereHasTheLinkGone = Object;
                                                                                  var whatWasTheLinkName = Object;
                                                                                
                                                                                  if (myOldLink.status == 1852797549) { // *** LINK O.K. ***
                                                                                  
                                                                                    myNewLinkName = 'PREPENDED_P' + myPageNumber + "_image" + myImageNumber + imageExtension;

                                                                                    var myOldImageFile = new File(myOldLink.filePath);
                                                                                    var myOldPath = myOldImageFile.toString();
                                                                                    var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);
                                                                                        
                                                                                    myOldImageFile.rename(myNewLinkName);
                                                                                    myOldLink.relink(myOldImageFile);
                                                                                    myOldLink.update();
                                                                                  
                                                                                    whereHasTheLinkGone[myOldLinkName] = myOldImageFile;
                                                                                    whatWasTheLinkName[myOldLinkName] = myNewLinkName;
                                                                                  
                                                                                    feedback("LINK O.K. : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);
                                                                                  
                                                                                    imagesPerPageCounter++;
                                                                                
                                                                                  } else { // LINK BROKEN
                                                                                
                                                                                    // ********** HOW CAN I LINK TO THE RENAMED IMAGE HERE ? **********
                                                                                  
                                                                                    feedback("LINK MISSING : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);
                                                                                
                                                                                  }
                                                                                }
                                                                              }

                                                                              function zeros3(myNumber) {
                                                                                if (myNumber >= 1 && myNumber <= 9) {
                                                                                  x =  "0" + "0" + myNumber;
                                                                                }
                                                                                else if (myNumber >= 10 && myNumber <= 99) {
                                                                                  x = "0" + myNumber;
                                                                                }
                                                                                else if (myNumber >= 100 && myNumber <= 999) {
                                                                                  x = myNumber;
                                                                                }
                                                                                return x;
                                                                              }

                                                                              function zeros2(myNumber) {
                                                                                if (myNumber >= 1 && myNumber <= 9) {
                                                                                  x =  "0" + myNumber;
                                                                                }
                                                                                else if (myNumber >= 10 && myNumber <= 99) {
                                                                                  x = myNumber;
                                                                                }
                                                                                return x;
                                                                              }

                                                                              function feedback(message) {
                                                                                if (messageCounter++ < 10) {
                                                                                  alert(message);
                                                                                }
                                                                              }


                                                                              Duncan
                                                                              • 36. Re: Re-link lots of images? Indesign CS3
                                                                                Level 1
                                                                                Hi Kasyan

                                                                                I have been playing around with this for some time now - although i am having problems with any image used more than once

                                                                                I am banging my head against a wall here - once the update is done on any first instance of an image, then subsequent ones fail [ i guess due to the fact that the link is now broken ]

                                                                                I have incorporated a check for an active / broken link, allowing different actions to be performed, and an Object to remember the revised link of pre-processed files, and a regular expression steal the characters after the last full stop [ in case the file extensions are 4 characters, for example ]

                                                                                I would be very grateful if you could help me with this

                                                                                Thank you!

                                                                                var myDoc = app.activeDocument;
                                                                                
                                                                                var myImages = myDoc.allGraphics;
                                                                                var seen = Object;
                                                                                var messageCounter = 0;

                                                                                for (var i = myImages.length-1; i >= 0; i--) {
                                                                                  var myOldLink = myImages[i].itemLink;
                                                                                  var myOldLinkName = myOldLink.name;
                                                                                  if (seen[myOldLinkName]) {
                                                                                    //alert("SEEN\n" + myOldLinkName);
                                                                                  } else {
                                                                                    //alert("FIRST SEEN\n" + myOldLinkName);
                                                                                    seen[myOldLinkName] = 1;
                                                                                  }
                                                                                }

                                                                                var myPages = myDoc.pages;
                                                                                for (var p = 0; p < myPages.length; p++) {
                                                                                  var myPageNumber = zeros3(myPages[p].name);
                                                                                  var myImageNumber;
                                                                                  var imagesPerPageCounter = 1;
                                                                                  //alert("PAGE " + myPageNum);

                                                                                  myImages = myPages[p].allGraphics;
                                                                                  for (i = myImages.length-1; i >= 0; i--) {
                                                                                    myOldLink = myImages[i].itemLink; // [ object ]
                                                                                    myOldLinkName = myOldLink.name;
                                                                                    myImageNumber = zeros2(imagesPerPageCounter);
                                                                                    var myFileExtensionRegEx = /\.[^.]+$/g;
                                                                                    var imageExtension = myOldLinkName.match(myFileExtensionRegEx);
                                                                                    var whereHasTheLinkGone = Object;
                                                                                    var whatWasTheLinkName = Object;
                                                                                  
                                                                                    if (myOldLink.status == 1852797549) { // *** LINK O.K. ***
                                                                                    
                                                                                      myNewLinkName = 'PREPENDED_P' + myPageNumber + "_image" + myImageNumber + imageExtension;

                                                                                      var myOldImageFile = new File(myOldLink.filePath);
                                                                                      var myOldPath = myOldImageFile.toString();
                                                                                      var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);
                                                                                          
                                                                                      myOldImageFile.rename(myNewLinkName);
                                                                                      myOldLink.relink(myOldImageFile);
                                                                                      myOldLink.update();
                                                                                    
                                                                                      whereHasTheLinkGone[myOldLinkName] = myOldImageFile;
                                                                                      whatWasTheLinkName[myOldLinkName] = myNewLinkName;
                                                                                    
                                                                                      feedback("LINK O.K. : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);
                                                                                    
                                                                                      imagesPerPageCounter++;
                                                                                  
                                                                                    } else { // LINK BROKEN
                                                                                  
                                                                                      // ********** HOW CAN I LINK TO THE RENAMED IMAGE HERE ? **********
                                                                                    
                                                                                      feedback("LINK MISSING : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);
                                                                                  
                                                                                    }
                                                                                  }
                                                                                }

                                                                                function zeros3(myNumber) {
                                                                                  if (myNumber >= 1 && myNumber <= 9) {
                                                                                    x =  "0" + "0" + myNumber;
                                                                                  }
                                                                                  else if (myNumber >= 10 && myNumber <= 99) {
                                                                                    x = "0" + myNumber;
                                                                                  }
                                                                                  else if (myNumber >= 100 && myNumber <= 999) {
                                                                                    x = myNumber;
                                                                                  }
                                                                                  return x;
                                                                                }

                                                                                function zeros2(myNumber) {
                                                                                  if (myNumber >= 1 && myNumber <= 9) {
                                                                                    x =  "0" + myNumber;
                                                                                  }
                                                                                  else if (myNumber >= 10 && myNumber <= 99) {
                                                                                    x = myNumber;
                                                                                  }
                                                                                  return x;
                                                                                }

                                                                                function feedback(message) {
                                                                                  if (messageCounter++ < 10) {
                                                                                    alert(message);
                                                                                  }
                                                                                }


                                                                                Duncan
                                                                                • 37. Re: Re-link lots of images? Indesign CS3
                                                                                  Kasyan Servetsky Level 5
                                                                                  Hi Duncan,

                                                                                  Here is a new version of the script, which deals with links placed more then once and extensions consisting of any number of characters. It’s not totally tested yet, so let me know if it works for you.

                                                                                  Kasyan
                                                                                  //------------------------------


                                                                                  #target indesign-5.0
                                                                                  var myDoc = app.activeDocument;
                                                                                  var myPages = myDoc.pages;
                                                                                  var myAllLinks = myDoc.links;
                                                                                  var myProcessedImages = new Array;

                                                                                  for (var p = 0; p < myPages.length; p++) {
                                                                                     var myPageNumber = pagenum(myPages[p].name);
                                                                                     var myImages = myPages[p].allGraphics;
                                                                                     var myImageCounter = 0; // set the counter of images to zero at start of each loop
                                                                                     for (i = myAllLinks.length-1; i >= 0 ; i--) {
                                                                                        var myLink = myAllLinks[i];
                                                                                        var myOldLinkName = myLink.name;
                                                                                        var myOldImageFile = new File (myLink.filePath);
                                                                                        var myOldPath = myOldImageFile.toString();
                                                                                           if (myIsInArray(myLink, myProcessedImages) == false) {
                                                                                           var myLinkUsage = LinkUsage(myLink);
                                                                                           myImageCounter ++;
                                                                                           var myImageNumber = pagenum(myImageCounter);
                                                                                           // now I assume that all extensions may consist of any number of characters
                                                                                           var myExtension = myOldLinkName.substr((myOldLinkName.lastIndexOf( "." )));
                                                                                           var myNewLinkName = "PAGE_" + myPageNumber  + "_image" + myImageNumber + myExtension;
                                                                                           var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);
                                                                                           myOldImageFile.rename(myNewLinkName);
                                                                                              if (myLinkUsage == 0) {
                                                                                                 myLink.relink (myNewFile);
                                                                                                 myLink.update();
                                                                                                 myProcessedImages.push(myLink);
                                                                                              }
                                                                                              else {
                                                                                                 var myMultyPlacedLinks = multyPlacedLinks(myLink);
                                                                                                 for (k = myMultyPlacedLinks.length-1; k >= 0 ; k--) {
                                                                                                    if (!myOldImageFile.exists){
                                                                                                       break;
                                                                                                    }
                                                                                                    myMultyPlacedLinks[k].relink (myOldImageFile);
                                                                                                    myMultyPlacedLinks[k].update();
                                                                                                 }
                                                                                              myProcessedImages.push(myLink);
                                                                                              }
                                                                                           }
                                                                                     }
                                                                                  }
                                                                                  function pagenum(myNumber){
                                                                                     if (myNumber >= 1 && myNumber <= 9)
                                                                                     {
                                                                                     x =  "0" + "0" + myNumber;
                                                                                     }
                                                                                     else if (myNumber >= 10 && myNumber <= 99)
                                                                                     {
                                                                                     x = "0" + myNumber;
                                                                                     }
                                                                                     else if (myNumber >= 100 && myNumber <= 999)
                                                                                     {
                                                                                     x = myNumber;
                                                                                     }
                                                                                  return x
                                                                                  }
                                                                                  function LinkUsage(myLink) {
                                                                                     var myLinkCounter = 0;
                                                                                        for (var myCounter =  0; myCounter < myAllLinks.length; myCounter++) {
                                                                                        if (myLink.filePath == myAllLinks[myCounter].filePath) {
                                                                                           myLinkCounter += 1;
                                                                                        }
                                                                                     }
                                                                                     return myLinkCounter
                                                                                  }
                                                                                  function multyPlacedLinks(myLink) {
                                                                                     var myMultyImages = new Array();
                                                                                     for (var myCounter =  0; myCounter < myAllLinks.length; myCounter++) {
                                                                                        if (myLink.filePath == myAllLinks[myCounter].filePath) {
                                                                                           myMultyImages.push(myAllLinks[myCounter]);
                                                                                        }
                                                                                     }
                                                                                  return myMultyImages;
                                                                                  }
                                                                                  function myIsInArray(myLink, myArray) {
                                                                                     var theResult = false;
                                                                                     for (myCounter = 0; myCounter < myArray.length; myCounter ++) {
                                                                                        if (myArray[myCounter].filePath == myLink.filePath) {
                                                                                           theResult = true;
                                                                                           break;
                                                                                        }
                                                                                     } 
                                                                                     return theResult;
                                                                                  }
                                                                                  • 38. Re: Re-link lots of images? Indesign CS3
                                                                                    Level 1
                                                                                    Hi Kasyan

                                                                                    Wow! I must have spent about 20 hours trying to solve this. The script worked beautifully.

                                                                                    I've been programming for fun since i was 12 - and now i am 39. I very rarely bump into anyone that impresses me - and i am certainly impressed with your understanding of this. I really don't know what you gain from spending your time helping people with their problems, but i am really grateful for the time you have spent helping me.

                                                                                    As i mentioned in a previous post, i do not want you to think i want you to do my work for me - i have spent hours going over every line of your script and plucking them apart until i finally understood how it all worked. It finally grasped it today - i think - and have included my version (a bit like a homework project!). If i have managed to understand your teachings, i will have a whole arsenal of tools to attack InDesign and automate all sorts of stuff in the future. And this could save me days. For this i am truly appreciative.

                                                                                    I would be (very) grateful for any comments on the script if you have any!

                                                                                    var myPages = app.activeDocument.pages;
                                                                                    
                                                                                    var myProcessed = Object;

                                                                                    for (var p = 0; p < myPages.length; p++) {

                                                                                    var myPageNumber = pad000(myPages[p].name);
                                                                                    var myImages = myPages[p].allGraphics;
                                                                                    var myImageCounter = 0;

                                                                                    for (i = myImages.length-1; i >= 0 ; i--) {

                                                                                      myImageCounter++;

                                                                                      var myLink = myImages[i].itemLink;
                                                                                      var myOldLinkName = myLink.name;

                                                                                      if (! myProcessed[myOldLinkName]) {
                                                                                       var myImageNumber = pad000(myImageCounter);
                                                                                       var myExtension = myOldLinkName.substr(myOldLinkName.lastIndexOf( "." ));
                                                                                       var myNewLinkName = "PAGE_" + myPageNumber  + "_image" + myImageNumber + myExtension;
                                                                                       var myOldImageHDfile = new File(myLink.filePath);
                                                                                       myOldImageHDfile.rename(myNewLinkName);
                                                                                       myProcessed[myOldLinkName] = myOldImageHDfile;
                                                                                      }
                                                                                      myLink.relink(myProcessed[myOldLinkName]);
                                                                                      myLink.update();

                                                                                    }
                                                                                    }

                                                                                    function pad000(myNumber) {
                                                                                    if (myNumber >= 1 && myNumber <= 9) {
                                                                                      x =  "0" + "0" + myNumber;
                                                                                    } else if (myNumber >= 10 && myNumber <= 99) {
                                                                                      x = "0" + myNumber;
                                                                                    } else if (myNumber >= 100 && myNumber <= 999) {
                                                                                      x = myNumber;
                                                                                    }
                                                                                    return x;
                                                                                    }


                                                                                    Kind regards
                                                                                    Duncan
                                                                                    • 39. Re: Re-link lots of images? Indesign CS3
                                                                                      Kasyan Servetsky Level 5
                                                                                      Nice code, Duncan. Its much more concise than mine. But never stop at what has been accomplished e.g. Id put in a function to check for missing/modified links at start of the script:


                                                                                      function checkLinkNormal(){
                                                                                         for(var myCounter = 0; myCounter < myDoc.links.length; myCounter++){
                                                                                         var myLink = myDoc.links[myCounter];
                                                                                            if (myLink.status != LinkStatus.normal){
                                                                                               if (myLink.status == LinkStatus.linkOutOfDate){
                                                                                                  myLink.show();
                                                                                                  alert ("This link is modified");
                                                                                                  myProblems++;
                                                                                                  }
                                                                                               else if (myLink.status == LinkStatus.linkMissing){
                                                                                                  myLink.show();
                                                                                                  alert ("This link is missing.");
                                                                                                  myProblems++;
                                                                                                  }
                                                                                               else if (myLink.status == LinkStatus.linkEmbedded){
                                                                                                  myLink.show();
                                                                                                  alert ("This link is embedded.");
                                                                                                  myProblems++;
                                                                                               }
                                                                                               exit();
                                                                                            }
                                                                                         }
                                                                                      }


                                                                                      >I really don't know what you gain from spending your time helping people with their problems

                                                                                      Scripting is my hobby, for me it is mental gymnastics, like playing chess. Im not programmer by background and a few years ago I couldnt even imagine that I would busy oneself with it. BTW Im 39 too. When I was making my baby steps in scripting, this forum helped me a lot to solve my problems, so now I try to help others as far as I can.

                                                                                      Kasyan
                                                                                      1 2 Previous Next