Skip to main content
Participant
June 28, 2023
Answered

Change image link bulk (file suffix) (script)

  • June 28, 2023
  • 1 reply
  • 398 views

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.");
This topic has been closed for replies.
Correct answer CarlosCanto

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

 

 

1 reply

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
June 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();

 

 

Participant
June 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.");



CarlosCanto
Community Expert
Community Expert
June 29, 2023

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.