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

Relink pictures

Community Beginner ,
Oct 18, 2017 Oct 18, 2017

Copy link to clipboard

Copied

We have several Illustrator files with huge embedded pictures (.jpg and .eps). What I need to do is to relink those pictures to some .psd files with the same file name. Doing this manually takes ages so I’m trying to write a script, but being a complete beginner I have no clue about how to do that.

Basically loop through the pictures and relink all of them to a psd file that has the same file name.

Example: picture.jpg -> relink to /images/picture.psd

I hope someone can help me out! Thanks.

TOPICS
Scripting

Views

588

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
Adobe
Valorous Hero ,
Oct 18, 2017 Oct 18, 2017

Copy link to clipboard

Copied

Try to run this little snippet on a test file which contains a couple .jpg and .eps links.. and let's see if it works!

#target illustrator

function test(){

  var doc = app.activeDocument;

  for(var i=0; i<doc.placedItems.length; i++){

       doc.placedItems.file = File(doc.placedItems.file.replace(/(\.jpg|\.eps)/, ".psd"));

  };

};

test();

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
Community Beginner ,
Oct 18, 2017 Oct 18, 2017

Copy link to clipboard

Copied

Thank you!

I will test it Friday when I get back to work.

Cheers

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
Community Beginner ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

Hello,

I tried to use the code but nothing happens, so I tried to add an alert to see what's actually going on; the alert(doc.placedItems.length) returns 0.

function test(){

  alert('hello');

  var doc = app.activeDocument;

  alert(doc.placedItems.length);

  for(var i=0; i<doc.placedItems.length; i++){

     

       alert(i);

       doc.placedItems.file = File(doc.placedItems.file.replace(/(\.jpg|\.eps)/, ".psd"));

   };

};

test();

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
Valorous Hero ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

Oh sorry, I didn't read carefully: you said the images you have are embedded.

Here's what you can do: open up your variables panel and do this for each of your images: click image, then use the Lego®-looking button at the bottom of the Variables panel to 'make content dynamic'. After all your images are made into variables, use the camera button at the top to capture a single dataset. Now, export an XML file using the 'save variables library' menu item in the Variables panel's fly-out menu. At this point you can open up the XML file and use text-replace to change all '.jpg' to .psd and so forth. Then when you're done text-replacing, save this XML file and re-import it inside of your Illustrator document. Now, if it does not happen instantly, selecting the first dataset after this new import will change all the image variables to get images from the new paths- relinking the files to .psd.

Let me know if you have questions.

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
Community Beginner ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

Hello,

Thank you for your reply.

I tried to follow your instructions but after I select the image and bring up the variables panel, the icon for 'make content dynamic' it's greyed out, the other button 'make visibility dynamic' it's working.

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
Valorous Hero ,
Oct 21, 2017 Oct 21, 2017

Copy link to clipboard

Copied

DOH! Once again, I did the same thing last year! ( File Location of Pasted Image  )

Okay, try to run this script and see if it's going to work:

#target illustrator

function test(){

var errorFiles = [];

var newPath = "~/Desktop"; // change this to your path

  var doc = app.activeDocument;

  var thisRaster, newPlaced, newFilePath;

  for (var i = doc.rasterItems.length - 1; i > -1; i--) {

  thisRaster = doc.rasterItems;

  try {

  if(thisRaster.hasOwnProperty('file') && thisRaster.file != ""){

  newFilePath = newPath + "/" + decodeURI(thisRaster.file.name).replace(/(\.jpg|\.eps|\.png)/, ".psd");

  if(!File(newFilePath).exists){

  throw new Error("File not found");

  }

  newPlaced = doc.placedItems.add();

  newPlaced.file = ( File(File(newFilePath).fsName) );

  newPlaced.move(thisRaster, ElementPlacement.PLACEBEFORE);

  newPlaced.top = thisRaster.top;

  newPlaced.left = thisRaster.left;

  newPlaced.width = thisRaster.width;

  newPlaced.height = thisRaster.height;

  thisRaster.remove();

  }

  } catch(e) {

  errorFiles.push(decodeURI(thisRaster.file.name));

  }

  }

  

  if(errorFiles.length > 0){

  alert("The following files had problems:\r" + errorFiles.join("\n"));

  }

};

test();

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
Community Beginner ,
Oct 24, 2017 Oct 24, 2017

Copy link to clipboard

Copied

I really appreciate your help, but unfortunately after playing with the script for a while I had to give up and start doing the job manually because of a lack of time.

All the best.

Rob

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
Valorous Hero ,
Oct 24, 2017 Oct 24, 2017

Copy link to clipboard

Copied

LATEST

Oh no! Sorry I couldn't help you.

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