Javascript für InDesign (Automatisch neuen Verknüpfungspfad aktualisieren) - Bräuchte Hilfe bei der Anpassung eines vorhandenen Scripts
Hallo,
ich versuche derzeit die Verknüpfungen meiner Bilder in InDesign mithilfe eines Scripts automatisch zu aktualisieren. Im Moment sind diese auf
C:\Artikelbilder\Bilder\Artikelnummer\Bild.psd
verknüpft.
Nun möchte ich den Pfad aller Bilder vollständig ändern. Gleich bleibt der eigentliche Dateiname, also:
D:\Artikelbilder\Artikelnummer\Bild.psd
Ich habe bereits ein Script gefunden, das funktioniert, allerdings nur, wenn die Datei nicht noch in einem weiteren Unterordner liegt, also so: "D\Artikelbilder\Bild.psd":
Gibt es eine Möglichkeit dieses Script so anzupassen, dass es auch Unterordner durchsucht, also ""D\Artikelbilder\Artikelnummer\Bild.psd"?
Vielen Dank bereits im Voraus.
ich versuche derzeit die Verknüpfungen meiner Bilder in InDesign mithilfe eines Scripts automatisch zu aktualisieren. Im Moment sind diese auf
C:\Artikelbilder\Bilder\Artikelnummer\Bild.psd
verknüpft.
Nun möchte ich den Pfad aller Bilder vollständig ändern. Gleich bleibt der eigentliche Dateiname, also:
D:\Artikelbilder\Artikelnummer\Bild.psd
Ich habe bereits ein Script gefunden, das funktioniert, allerdings nur, wenn die Datei nicht noch in einem weiteren Unterordner liegt, also so: "D\Artikelbilder\Bild.psd":
//Relink2NewPath.jsx
var myDoc = app.documents;
var myFolder = Folder.selectDialog("Neuer Pfad zu dem Bildern")+"";
myLinks = myDoc.links;
for (oneLink=myLinks.length-1;oneLink>-1;oneLink--) {
myLink = myLinks[oneLink];
myName = String(File.encode(myLink.name));
myNewLink = File(myFolder + "/" + myName);
try{
myLink.relink(myNewLink);
myLink.update();
}
catch(e){}
}
Gibt es eine Möglichkeit dieses Script so anzupassen, dass es auch Unterordner durchsucht, also ""D\Artikelbilder\Artikelnummer\Bild.psd"?
Vielen Dank bereits im Voraus.
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 309071
Url: https://administrator.de/contentid/309071
Ausgedruckt am: 24.11.2024 um 23:11 Uhr
12 Kommentare
Neuester Kommentar
Hi.
you should define a variable which is the current rootpath of the links:
Then do a "replace" of this folder in the filePath property of the links
Regards
you should define a variable which is the current rootpath of the links:
var oldroot = 'd:\Artikelbilder';
myNewLink = File(myLink.filePath.replace(oldroot, myFolder) + "/" + myName);
Ok, i see the problem, the paths in Indesign are written a little bit different, you have to write the old path in this format:
This worked with the active document without problems:
var oldPath = '/d/Artikelbilder';
var myDoc = app.activeDocument;
var oldPath = '/d/Artikelbilder';
var myFolder = Folder.selectDialog("Neuer Pfad zu dem Bildern");
for(var i = 0;i < myDoc.links.count();i++){
var myLink = myDoc.links[i];
var currentPath = File(myLink.filePath).path;
var myNewLink = File(currentPath.replace(oldPath,myFolder) + "/" + myLink.name);
try{
myLink.relink(myNewLink);
myLink.update();
}catch(e){
alert(e);
}
}
Zitat von @zlep01:
Might be my document (too many images?) but unfortunately it's still not working for me. The script crashed after a while.
Do I really need the "var oldPath"?
Yes you need it ...Might be my document (too many images?) but unfortunately it's still not working for me. The script crashed after a while.
Do I really need the "var oldPath"?
Because the original script worked with all images which aren't in subfolders.
Yes but this is another condition, the script now needs to know which part of the path it needs to replace with the new one now, guy!I thought it would be possible to just change the script a little bit so that it also searches for images in subfolders.
Nothing is "searched" in the script, the old path is only interchanged with a the new one you choose! But if you have subfolders then the script needs to know which is the root of the old folder.Put all other commands also in the try catch part then you see why it is not working with your document.
var myDoc = app.activeDocument;
var oldPath = '/d/Artikelbilder';
var myFolder = Folder.selectDialog("Neuer Pfad zu dem Bildern");
for(var i = 0;i < myDoc.links.count();i++){
try{
var myLink = myDoc.links[i];
var currentPath = File(myLink.filePath).path;
var myNewLink = File(currentPath.replace(oldPath,myFolder) + "/" + myLink.name);
myLink.relink(myNewLink);
myLink.update();
}catch(e){
alert(e);
}
}
As i said file paths have another format especially when using special chars like spaces. Encode the file path:
or also this is possible:
Have a look at the reference!
http://jongware.mit.edu/idcs5js/pc_File.html
If you want you can also replace this static variable by the same dialog for choosing the target folder, like in this example:
This all works without problems and is tested locally with InDesign CS6.
I have said all now, i'm out. If you need more support you can contact me via PM but that's not for free anymore.
Happy coding
Regards
highload
var oldPath = String(File.encode('/p/02_Kataloge/01_Gesamtkataloge/Katalog Nr 9/InDesign/Firma 2015/01 Thema_2015/Links'));
var oldPath = String(File.encode('P:\\02_Kataloge\\01_Gesamtkataloge\\Katalog Nr 9\\InDesign\\Firma 2015\\01 Thema_2015\\Links'));
http://jongware.mit.edu/idcs5js/pc_File.html
If you want you can also replace this static variable by the same dialog for choosing the target folder, like in this example:
var myDoc = app.activeDocument;
var myCurrentRoot = Folder.selectDialog("Jetziger Pfad zu den Bildern");
var myTargetRoot = Folder.selectDialog("Neuer Pfad zu dem Bildern");
for(var i = 0;i < myDoc.links.count();i++){
try{
var myLink = myDoc.links[i];
var currentPath = File(myLink.filePath).path;
var myNewLink = File(currentPath.replace(myCurrentRoot,myTargetRoot) + "/" + myLink.name);
myLink.relink(myNewLink);
myLink.update();
}catch(e){
alert(e);
}
}
I have said all now, i'm out. If you need more support you can contact me via PM but that's not for free anymore.
Happy coding
Regards
highload
I tested it, 100% working,sorry !!! I can show you a video that it's working if you wish....
This script is only replacing the old root path with the new one, so nothing special and very easy !! The rest of the path part (the subfolders) remain the same, so exactly what you want.
You should take a JavaScript course to understand the script.
This script is only replacing the old root path with the new one, so nothing special and very easy !! The rest of the path part (the subfolders) remain the same, so exactly what you want.
You should take a JavaScript course to understand the script.
Zitat von @zlep01:
It's working if the images are not in subfolders, but that's not what I need (see post 1).
I know i tested it explicitly with this condition!It's working if the images are not in subfolders, but that's not what I need (see post 1).
My images are now in subfolders. Before, they alll were in one folder.
BEFORE:
P:\xxxx/xxxx/xxxx/xxxxx/xxxx/image1234.psd
P:\xxxx/xxxx/xxxx/xxxxx/xxxx/image2345.psd
P:\xxxx/xxxx/xxxx/xxxxx/xxxx/image3456.psd
You are mixing backslash and slash !BEFORE:
P:\xxxx/xxxx/xxxx/xxxxx/xxxx/image1234.psd
P:\xxxx/xxxx/xxxx/xxxxx/xxxx/image2345.psd
P:\xxxx/xxxx/xxxx/xxxxx/xxxx/image3456.psd
NOW:
P:\images/image1234/image1234.psd
P:\images/image2345/image2345.psd
P:\images/image3456/image3456.psd
So please describe your intention exactly, before i'm again writing scripts for nothing , thanks....
So what's the job now ?