Copy link to clipboard
Copied
HI,
Not very familiar with scripting for Illustrator. Need to create a script, preferably for batches of files. Need to add small extension to artboard to files and auto add the file name and save. Is this possible? Any help would be greatly appreciated.
Copy link to clipboard
Copied
First snippet:
Here we generate a copy of your actual AI file. Therefore we extract the file name, add an extension as you like, and save the copy on your desktop. After that it re-opens the original file.
var doc = app.activeDocument;
var original_file = doc.fullName; // we need this to return to original file
var arr = doc.name.split(".");
var extension = "";
if (arr.length>1) extension = "." + arr.pop();
var filename = arr.join(".");
var aiSuff = '_version1.ai'; // put in any extension you like but keep suffix .ai
var name_ai = filename + aiSuff;
var export_folder = "~/Desktop"; // define the place where to save the copy
saveCopyAsAI (name_ai);
function saveCopyAsAI (nameAI) {
var packaged_file = null;
packaged_file = File (export_folder + "/" + nameAI);
var save_options = new IllustratorSaveOptions();
save_options.embedICCProfile = false;
save_options.pdfCompatible = false
doc.saveAs (packaged_file, save_options);
doc.close ();
app.open (File (original_file));
}
Next step would be:
You'll have to name your artboard, then extract the name and add them to "name_ai". If you have files with more than one artboard you'll have to define which artboard's name should be used. In case you only have 1 artboard just add:
var abName = app.activeDocument.artboards[0].name;
and change
var aiSuff = "_" + abName + ".ai";
Second snippet:
Opens a dialog where you have to choose a folder containig multiple AI files.
var dir = Folder.selectDialog("Choose folder containing .ai files");
var files = dir.getFiles("*.ai");
for(var f = 0; f < files.length; f++){
var doc = app.open(files
); //Your processing
doc.close(SaveOptions.DONOTSAVECHANGES);
}
Copy link to clipboard
Copied
HI,
Thanks for this! I have very little experience with Java. I consolidated the code you sent in Extendscript. It doesnt appear to work. Ideally we need to have this work through an action and overwrite the file in a folder. This would be a batch type action.
Any suggestions?
var doc = app.activeDocument;
var original_file = doc.fullName; // we need this to return to original file
var arr = doc.name.split(".");
var extension = "";
if (arr.length>1) extension = "." + arr.pop();
var filename = arr.join(".");
var aiSuff = '_version1.ai'; // put in any extension you like but keep suffix .ai
var name_ai = filename + aiSuff;
var export_folder = "~/Desktop"; // define the place where to save the copy
saveCopyAsAI (name_ai);
function saveCopyAsAI (nameAI) {
var packaged_file = null;
packaged_file = File (export_folder + "/" + nameAI);
var save_options = new IllustratorSaveOptions();
save_options.embedICCProfile = false;
save_options.pdfCompatible = false
doc.saveAs (packaged_file, save_options);
doc.close ();
app.open (File (original_file));
}
var abName = app.activeDocument.artboards[0].name;
var aiSuff = "_" + abName + ".ai";
var dir = Folder.selectDialog("Choose folder containing .ai files");
var files = dir.getFiles("*.ai");
for(var f = 0; f < files.length; f++){
var doc = app.open(files
//Your processing
doc.close(SaveOptions.DONOTSAVECHANGES);
}
Copy link to clipboard
Copied
I would have needed more clarification regarding the objective here:
Need to add small extension to artboard to files and auto add the file name and save
Is the 'small extension', like you're adding some more space to the artboard and widening it? Or are you adding a word to the artboard names. Many interpretations could emerge from every several words in this statement.
Copy link to clipboard
Copied
HI,
Yes, the intent would be to add space on the bottom of the artboard, add the text for the file name to the bottom left and save over the file in the original location.
Ideally there would be 4 versions for files that are at 100, 50, 25 and 10% scale, so the text should scale accordingly.
Copy link to clipboard
Copied
Salut,
J'ai réalisé un script qui je pense correspond à ta demande :
Avant en haut et après en bas.
Me contacter par mail
elleere
Find more inspiration, events, and resources on the new Adobe Community
Explore Now