Copy link to clipboard
Copied
Hello
Could someone help with script.
I have document with 6 linked ai files. The same 6 files.And 1 text box.
I need to relink for example dump.ai with files from text file.
Text file with paths to files that need to be relinked.
text file:
c:\temp\a1.ai
c:\temp\a2.ai
etc
I have over 300 files to relink. Could the text in text box be as the name of the file that is linked?
It will be great that files with new link have the same name as relinked ai.
They can be created in c:\temp\merge\
script->open ai with dump.ai->relink with a1.ai and change text to a1->save to c:\temp\merge\a1.ai ...
REALLY THNKS FOR HELP !
Copy link to clipboard
Copied
Hello,
what's the structure of existing files?
Should there be a prompt to ask for location of txt file, or it's placed in same folder as the ai file and have some specific name?
You can send mi private message, in your native language, as i assume we live in same country ![]()
Copy link to clipboard
Copied
JavaScript version:
function getDataFile() {
var chosedFile = new File();
chosedFile = chosedFile.openDlg('Chose text file, to read paths', '*.txt', false);
if (chosedFile.exists) {
return chosedFile;
}
return undefined;
}
function readPaths(fileToRead) {
var paths = [];
fileToRead.open('read');
while (!fileToRead.eof) {
var textLine = fileToRead.readln();
paths.push(textLine);
}
fileToRead.close();
return paths;
}
function replaceLinks(documentWithLinks, newLinkFile) {
for (var i = 0; i < documentWithLinks.placedItems.length; i += 1) {
var item = documentWithLinks.placedItems;
if (item.locked) {
item.locked = false;
}
if (newLinkFile.exists) {
item.relink(newLinkFile);
}
}
}
function saveFile(documentToSave, pathToSave, fileName) {
var fileToSave = new File(pathToSave + fileName);
documentToSave.saveAs(fileToSave);
return fileToSave;
}
function main() {
var paths = readPaths(getDataFile());
var document = app.activeDocument;
var savePath = '\\Skrypty\\Kod\\Illustrator\\adobe-forums\\relink_files_txt_file_paths\\Files\\Merged\\';
for (var i = 0; i < paths.length; i += 1) {
var path = paths;
var textToChange = document.textFrames[0];
var newLink = File(path);
var fileName = path.split('\\').pop();
replaceLinks(document, newLink);
textToChange.contents = path.split('\\').pop().split('.').shift();
saveFile(document, savePath, fileName);
}
}
main();
And here, the typescript: adobe-forums-scripts/relink_files_txt_file_paths.ts at relink_files_txt · lumenn/adobe-forums-script...
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more