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

Change image link bulk (file suffix) (script)

New Here ,
Jun 28, 2023 Jun 28, 2023

I have a mass of images in Illustrator that have always been stored as PSD. The PSD files have now been saved as "TIF". The path and file name remain the same, only the suffix changes from PSD - TIFF.

Is it possible to write a script for this? I have tried the following, but unfortunately without result.

 

// Pfade zu den Bildern vor und nach der Änderung
var alterSuffix = ".psd";
var neuerSuffix = ".tif";

// Durchläuft alle Verknüpfungen im Dokument
for (var i = 0; i < app.activeDocument.placedItems.length; i++) {
  var verknuepfung = app.activeDocument.placedItems[i];

  // Überprüft, ob die Verknüpfung geladen ist und eine Datei zugeordnet hat
  if (verknuepfung.status == 1 && verknuepfung.file != null && verknuepfung.file.exists) {
    var alterDateiname = verknuepfung.file.fullName;
    var neuerDateiname = alterDateiname.toString().replace(alterSuffix, neuerSuffix);

    // Aktualisiert die Verknüpfung mit dem neuen Dateinamen
    verknuepfung.file = new File(neuerDateiname);
    verknuepfung.reload();
  }
}

// Benachrichtigung über abgeschlossenen Vorgang
alert("Bildverknüpfungen wurden aktualisiert.");
TOPICS
Scripting
378
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

correct answers 1 Correct answer

Community Expert , Jun 28, 2023 Jun 28, 2023

the reason it doesn't work is that PladedItem doesn't have a "status" property, so none of the images are actually processed. Was the script generated by chatGPT?

 

remove this and you'll be on your way

verknuepfung.status == 1 && 

remove this as well

verknuepfung.reload();

 

 

Translate
Adobe
Community Expert ,
Jun 28, 2023 Jun 28, 2023

the reason it doesn't work is that PladedItem doesn't have a "status" property, so none of the images are actually processed. Was the script generated by chatGPT?

 

remove this and you'll be on your way

verknuepfung.status == 1 && 

remove this as well

verknuepfung.reload();

 

 

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

Thank you CarlosCanto for your answer.

What is the script generated by chatGPT? I found a similar script in a forum that didn't work and tried to fix it with chatGPT, so yes. 🙈

Your suggestion helped and at least it shows that it interprets file names correctly.

Now I get the message:
Error 9080: Unable to set placed item's file, is the file path provided valid? Or try to use the raster item instead.
Line: 16
->
verknuepfung.file = new File(neuerDateiname);


Remark:
It works like this when the ai. file has been packaged and files are in the "Link" folder. Works fine for me - Big thanks

Finished script:

// Pfade zu den Bildern vor und nach der Änderung

var alterSuffix = ".psd";
var neuerSuffix = ".tif";

// Durchläuft alle Verknüpfungen im Dokument
for (var i = 0; i < app.activeDocument.placedItems.length; i++) {
  var verknuepfung = app.activeDocument.placedItems[i];

  // Überprüft, ob die Verknüpfung geladen ist und eine Datei zugeordnet hat
  if (verknuepfung.file != null && verknuepfung.file.exists) {
    var alterDateiname = verknuepfung.file.fullName;
    var neuerDateiname = alterDateiname.toString().replace(alterSuffix, neuerSuffix);

    // Aktualisiert die Verknüpfung mit dem neuen Dateinamen
    verknuepfung.file = new File(neuerDateiname);
  }
}



// Benachrichtigung über abgeschlossenen Vorgang
alert("Bildverknüpfungen wurden aktualisiert.");



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
Community Expert ,
Jun 29, 2023 Jun 29, 2023
LATEST

thanks for confirming, chatGPT is great for getting things started, but most times it hallucinates, it creates properties out of thin air. 

 

glat to hear it works for you now.

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