Skip to main content
Participant
September 21, 2016
Question

Script to bulk update linked image paths

  • September 21, 2016
  • 3 replies
  • 3259 views

Hi,

We have changed our file server and now all our Illustrator files have broken links. I have found scripts for InDesign to help with this but nothing for Illustrator. Can anyone help with a script to update the path of all linked images in all Illustrator files?

The folder structure is all the same, just the server name has changed.

Thanks,

Michael

This topic has been closed for replies.

3 replies

Inspiring
September 2, 2022

Has a solutin been found for this yet?
 I am in the same situation. I have thousands of files that all have linked images in them. I am switching over to a new server and every link is going to be broken.

I need to be able to automate going through each file an resaving each file after updating the path information.

o-marat
Inspiring
September 24, 2016

Illustrator's files – is just a text files. It may be possible to apply some tool of global replace text in files? Like Total Commander or Power Grep.

Inspiring
September 9, 2022

Hey, yes, you might be onto something here!
 I renamed a .ai file to .txt and was able to open and find instances of the linked files paths.

It might be an easier write a Python program to search and replace the needed paths.

I'm not familiar with Total Commander or Power Grip. I'll look into those as they might do these things out of the box as you are suggesting.

Silly-V
Legend
September 21, 2016

You can do this in Illustrator without scripting, even, in this round-about way:

Go through your linked images and attach a dynamic image variable to each one ( a script can help if you have a large amount ) by selecting the image and using the lego-looking button at the bottom of the Variables panel (Window > Variables).

Once all the images are assigned a variable, use the Camera button on the Variables panel to capture the only data set you will need for this: "Data Set 1". Now that the dataset is captured, use the export XML command in the flyout menu of the Variables panel and save a 'variables.xml' file somewhere easily found. Open this file in a text editor and you will see an XML file which lists all the variables as XML tags and the file path to the previously working file as the contents of those tags. Now what you need to do is find and replace all of the occurrences of your old server name with your new one. After this text replacement operation, save the file and import it back into the Illustrator document by using the flyout menu inside of the Variables panel once again. And, well, that's it - you're done! It's still a bunch of clicks, but it's more accurate and way less clicks than having to relink each file manually. If the amount of images makes assigning a new variable to each one too much of a pain, this whole routine, or part of it can also be made into a script.

Participant
September 21, 2016

Thanks very much for your help, that certainly sounds like a reasonable method, however as you mention there are too many images in all different folders to try and go through and assign new variables manually, so I guess I need the script which I have no idea how to do...

Silly-V
Legend
September 22, 2016

This snippet ought to help you with the variable assignments. After running this, open your Variables panel and export your xml file. When you open the xml file in a text editor, do a Replace-All for instances of your old server name:

Find: "/old-server/"

Replace: "/new-server/"

Then save the xml file and import it back into your document - it should magically update.

#target illustrator

function test(){

  var doc = app.activeDocument, newVar, thisImage, newDataSet;

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

  thisImage = doc.placedItems;

  newVar = doc.variables.add();

  newVar.kind = VariableKind.IMAGE;

  newVar.name = "image_" + (i + 1);

  thisImage.contentVariable = newVar;

  }

  newDataSet = doc.dataSets.add();

  newDataSet.name = "image_collection";

};

test();