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

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

Explorer ,
Apr 10, 2023 Apr 10, 2023

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
1.0K
Translate
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
Explorer ,
Jun 16, 2023 Jun 16, 2023

Im Crying.jpg

It is so sad 😞

Translate
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

Hi @Oleh BetterMe  did you work this out in the end? ðŸ¤ž

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

Translate
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

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.

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

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

Translate
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

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

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

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...

Translate
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

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.

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

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)

Translate
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
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

Translate
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