Copy link to clipboard
Copied
Dear Friends,
Hi all, I need to relink lots of -missing- images (i.e. "K_MNYCEPT221161_C01PT_002T.ai") to (i.e. "K_MNLESE850231_C01PT_002T.ai"). I have listed my coding below, tell one good suggestion friends.
Application version: Cs6 indesign
var
mLinks = app.activeDocument.links.everyItem().getElements(),
cLink, cFile;
alert(mLinks.length)
while ( cLink = mLinks.pop() )
alert(cLink.length)
{
if (cLink.status == LinkStatus.NORMAL) continue;
cFile = File(cLink.name.replace("K_MNYCEPT221161_","K_MNLESE850231_") );
if ( !cFile.exists ) continue;
cLink.relink(cFile);
}
Thanks in advance,
This script works on MacOS 10.11.2 & CS6
I add console log in the code, give me the result ...
...var mLinks = app.activeDocument.links.everyItem().getElements(), cLink, cFile;
alert(mLinks.length)
while ( cLink = mLinks.pop() ){
$.writeln('Link path : ' + cLink.filePath)
if (cLink.status == LinkStatus.NORMAL) { continue; }
cFile = File(cLink.filePath.replace("page","pages") );
$.writeln('New Link path : ' + cFile.fsName)
$.writeln('New file exist : ' + cFile.exists)
if ( !cFile.exists
Copy link to clipboard
Copied
Hi,
some mistakes :
1°) continue syntax
2°) alert(cLink.length) is wrong, cLink is a object
3°) cLink.name replaced by cLink.filePath
var mLinks = app.activeDocument.links.everyItem().getElements(), cLink, cFile;
alert(mLinks.length)
while ( cLink = mLinks.pop() ){
if (cLink.status == LinkStatus.NORMAL) { continue; }
cFile = File(cLink.filePath.replace("K_MNYCEPT221161_","K_MNLESE850231_") );
if ( !cFile.exists ){ continue; }
cLink.relink(cFile);
}
Copy link to clipboard
Copied
Hi Ronald
Sorry for the late replay,
I have run your coding cs6, but images not relink and replace here. what can i do friend.
Thanks your quick replay Ronald.
Thanks in advance
Copy link to clipboard
Copied
Hi,
The path of good-image must be the same that the path of missing-image
Copy link to clipboard
Copied
Hi Ronald,
Yes - same path:
Thanks
Copy link to clipboard
Copied
This script works on MacOS 10.11.2 & CS6
I add console log in the code, give me the result ...
var mLinks = app.activeDocument.links.everyItem().getElements(), cLink, cFile;
alert(mLinks.length)
while ( cLink = mLinks.pop() ){
$.writeln('Link path : ' + cLink.filePath)
if (cLink.status == LinkStatus.NORMAL) { continue; }
cFile = File(cLink.filePath.replace("page","pages") );
$.writeln('New Link path : ' + cFile.fsName)
$.writeln('New file exist : ' + cFile.exists)
if ( !cFile.exists ){ continue; }
cLink.relink(cFile);
}
Copy link to clipboard
Copied
Hi Ronald,
Script is working good,
Thank U so match Ronald,
Thanks
Copy link to clipboard
Copied
Hello Ronald
Great! I have been looking for something like this the whole Day! And this script seems to work like a charm. Thanks a lot! It even works in CS 5.5, if anybody wonders.
How would I proceed if I wanted to look for multiple strings to replace? Say: "2015.psd" to "2015_CMYK_C.psd" and "2015_U.psd" to "2015_CMYK_U.psd"? And possibly even more?
Thanks for any Help!
Best, Christoph
Copy link to clipboard
Copied
Hi Christoph,
Just a quick update ... (not tested)
var mLinks = app.activeDocument.links.everyItem().getElements(), cLink, cFile;
alert(mLinks.length)
while ( cLink = mLinks.pop() ){
$.writeln('Link path : ' + cLink.filePath)
if (cLink.status == LinkStatus.NORMAL) { continue; }
if (cLink.filePath.match("2015.psd")) {
cFile = File(cLink.filePath.replace("2015.psd","2015_CMYK_C.psd") );
}
if (cLink.filePath.match("2015_U.psd")) {
cFile = File(cLink.filePath.replace("2015_U.psd","2015_CMYK_U.psd") );
}
$.writeln('New Link path : ' + cFile.fsName)
$.writeln('New file exist : ' + cFile.exists)
if ( !cFile.exists ){ continue; }
cLink.relink(cFile);
}
Copy link to clipboard
Copied
Ronald, this works. Thanks a lot!