Monday, March 06, 2006

 

Replacing Links

A U2U forum visitor posted a request for a script to replace linked color images with black & white (grayscale, probably) equivalent images using a particular naming scheme. Here's the script I created:
//DESCRIPTION: Replace color linked images with BW alternates

 /*
   Color images have "_cp" in their names; BW have "_bw"
 */

myDoc = app.activeDocument;
myLinks = myDoc.links;
for (j = myLinks.length - 1; j >= 0; j--) {
  myName = myLinks[j].filePath;
  myNewName = myName.split("_cp").join("_bw");
  if (myName != myNewName) {
    // Original link includes "-cp" in name
    myNewImageFile = File(myNewName);
    if (!myNewImageFile.exists) {
     alert ("Can't find file: " + myNewName);
      continue;
    }
    myLinks[j].relink(myNewImageFile);
    myLinks[j].update();
  }
}
It occurred to me having written the script for the situation where the two sets of images are in the same folder, the logic for converting the names will also work if the two sets are segregated into two side-by-side folders that use the same naming trick to distinguish one from the other.

PS: Things have been very hectic lately getting huge jobs out the door, so I've neglected the blog some. Hopefully, this will change now that the jobs are complete.

Comments:
I was able to get this script to work in CS3 with one document, but in a different document Indesign crashes when the script is run. As far as I can tell, both documents are very similar. Any ideas?

Thanks!
 
Hi!
Script works with CS3 fine!

I'm just thinking on, what if I only want to change the selected links(objects).
I tried to change app.activeDocument to app.selection, but it doesn't works with the for cycle.
 
Scripts can't see what's selected in a panel, I'm afraid. To work with a selection, the script would have to put up a dialog with the links in a list or drop-down and the user would select from that.

Dave
 
Hi Dave!
I need scripe for indesine
Image replacing same name b/w pic , with same name colour pic differance folder how relink.
Thanks
 
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?