Skip to main content
Participant
April 17, 2008
Pregunta

Re-link lots of images? Indesign CS3

  • April 17, 2008
  • 70 respuestas
  • 15111 visualizaciones
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
Este tema ha sido cerrado para respuestas.

70 respuestas

Kasyan Servetsky
Legend
August 27, 2008
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

.name);
var myImages = myPages

.allGraphics;
for (i = myImages.length-1; i >= 0 ; i--) {
var myLink = myImages.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
}

Kasyan Servetsky
Legend
August 27, 2008
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

.name);
var myImages = myPages

.allGraphics;
for (i = myImages.length-1; i >= 0 ; i--) {
var myLink = myImages.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
}

Kasyan Servetsky
Legend
August 27, 2008
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

.name);
for (i = myImages.length-1; i >= 0 ; i--) {
var myLink = myImages.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
}

Participating Frequently
August 26, 2008
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
c.pfaffenbichler
Community Expert
Community Expert
August 25, 2008
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.
Kasyan Servetsky
Legend
August 25, 2008
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
c.pfaffenbichler
Community Expert
Community Expert
August 25, 2008
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.
Kasyan Servetsky
Legend
August 22, 2008
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
Kasyan Servetsky
Legend
August 21, 2008
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
Participant
August 14, 2008
Kasyan, you totally rock! I used your script and it worked great. Thank you for saving my wrists from carpal tunnel!!