• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How can relink and renaming image

Contributor ,
Jan 06, 2016 Jan 06, 2016

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,

TOPICS
Scripting

Views

725

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jan 07, 2016 Jan 07, 2016

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

...

Votes

Translate

Translate
Enthusiast ,
Jan 06, 2016 Jan 06, 2016

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);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 07, 2016 Jan 07, 2016

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 07, 2016 Jan 07, 2016

Copy link to clipboard

Copied

Hi,

The path of good-image must be the same that the path of  missing-image

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 07, 2016 Jan 07, 2016

Copy link to clipboard

Copied

Hi Ronald,

Yes - same path:

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 07, 2016 Jan 07, 2016

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);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 07, 2016 Jan 07, 2016

Copy link to clipboard

Copied

Hi Ronald,

Script is working good,

Thank U so match Ronald,

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 16, 2016 Feb 16, 2016

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 16, 2016 Feb 16, 2016

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); 

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 16, 2016 Feb 16, 2016

Copy link to clipboard

Copied

LATEST

Ronald, this works. Thanks a lot!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines