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

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

Community Beginner ,
Apr 10, 2023 Apr 10, 2023

Copy link to clipboard

Copied

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

 

TOPICS
Error or problem , FAQ , How to , Import and export , Scripting

Views

319

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 ,
Jun 16, 2023 Jun 16, 2023

Copy link to clipboard

Copied

Im Crying.jpg

It is so sad 😞

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 ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

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

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 ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

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 😞

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 ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

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.

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 ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

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

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 ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

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

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 ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

Sounds good and simple, but there is a couples problems
1. What if the original names have been changed in the project panel? Then the new imported name will not match.
2. How to know, wich type of import to use ? The illustrator can be layered or solid...

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 ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

1. Precisely why I said it was dangerous.
2. Precisely why I said the number of layers and the name of the layers must be the same of the ai or psd file and it has to be the same import type.

Since you seem to have experience, I figured you have also checked the tool guide on this?
An ImportAsType enumerated value; read/write. One of:
• ImportAsType.COMP_CROPPED_LAYERS
• ImportAsType.FOOTAGE
• ImportAsType.COMP
• ImportAsType.PROJECT

These are the types of import.
Lots of restrictions for what you want to achieve though.

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 ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

These restrictions are extremely annoying...
I'm actually trying to recreate the Collect function. It somehow knows how to reassign the path of one Illustrator file to a new one.

Thanks for the help)

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 ,
Dec 05, 2023 Dec 05, 2023

Copy link to clipboard

Copied

LATEST

Oh I tried that before. I think I managed to do it by scripting things to save as a mogrt, changing it to a .zip, unpacking it, but it wasn't a very good method because it runs very slowly. Good luck!
https://community.adobe.com/t5/after-effects-discussions/collect-files-scriptable/td-p/11431767

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