Skip to main content
Known Participant
April 10, 2023
Question

How to replace path of an illustrator file to a new one using ExtendScript ?

  • April 10, 2023
  • 2 replies
  • 1298 views

Hi! I have a problems with one script... i need a simple thing - replacing one path of the file to another.
Its really easy for any footage, (little harder for sequence, but still possible).
BUT
How to do this with illustrator/photoshop files that contain layers? If im apply the usual method to them, which I wrote below, then all layers in my project will be replaced with a single file. How to just replace the path, with keep separating the layers in my project ?
I should note that the .ai (or .psd) file in the old path and in the new one are absolutely identical just different path.

// get the current project
var curProject = app.project;

// create undo group
app.beginUndoGroup("Replace Illustrator Footage Path");

// iterate through all the items in the project
for (var i = 1; i <= curProject.numItems; i++) {
var curItem = curProject.item(i);
// check if the item is an Illustrator file
if (curItem.file instanceof File && curItem.file.name.match(/\.ai$/i)) {
// replace the file path
var curFilePath = curItem.file.fsName;
var newFilePath = new File("C:\\Users\\Alienware\\Downloads\\test PbyBM folder\\new\\" + curItem.file.name);
curItem.replace(newFilePath);
// alert the user that the file path has been updated
}
}
alert("File path updated.");

// close undo group
app.endUndoGroup();

 

This topic has been closed for replies.

2 replies

Meng Zhiqun
Inspiring
November 23, 2023

For this to work, the number of layers and the name of the layers must be the same of the ai or psd file. It could only be replaced by a name search which is a rather dangerous workflow. I don't think there are other alternatives atm.

Known Participant
November 23, 2023

"by a name search" you mean by hand ?
I know this... but I need to do it with a script

Meng Zhiqun
Inspiring
November 27, 2023

Nope. I meant by script.
You have to 1. Import the file to AE, 2. Loop through all the items in the project window, 3. Find the name of the layer, before replacing it

Known Participant
June 16, 2023

It is so sad 😞

Participant
November 22, 2023

Hi @Oleh BetterMe  did you work this out in the end? 🤞

Known Participant
November 23, 2023

Hello! Unfortunately no, it didn’t work out for me(
I tried various scripts, such as File Hunter and Relincker, but even there, the layers of the illustrator file are replaced with a solid file 😞