Copy link to clipboard
Copied
I have a ton of .ai files(1000+), in folders, that I want to copy/convert to .eps files. I am trying to figure out a script but do not know enough about it to do it. Anyone know of an easy way to do this?
Thanks
Cheryl
...//Some utils to retrieve files in folders and subfolders
var api = {
getFiles : function ( fo, aExtensions, bRecursive, aFiles, includeFolder )
{
var exts = aExtensions? aExtensions.join("|") : ".+" ;
var pattern = new RegExp ( "\\.("+exts+")$");
!aFiles && aFiles = [];
var filterFunction = function(file)
{
return pattern.test ( file.name );
}
if ( bRecursive && fo.name.indexOf ( ".")!=0 )
{
var foFiles = fo.getFiles();
while ( f = foFiles.shift() )
{
if ( f instanceof Folder )
{
if (includeFolder===true) files[
Copy link to clipboard
Copied
I am using CS6.
Copy link to clipboard
Copied
//Some utils to retrieve files in folders and subfolders
var api = {
getFiles : function ( fo, aExtensions, bRecursive, aFiles, includeFolder )
{
var exts = aExtensions? aExtensions.join("|") : ".+" ;
var pattern = new RegExp ( "\\.("+exts+")$");
!aFiles && aFiles = [];
var filterFunction = function(file)
{
return pattern.test ( file.name );
}
if ( bRecursive && fo.name.indexOf ( ".")!=0 )
{
var foFiles = fo.getFiles();
while ( f = foFiles.shift() )
{
if ( f instanceof Folder )
{
if (includeFolder===true) files[ files.length ] = f;
this.getFiles ( f, aExtensions, true, aFiles );
}
if ( f instanceof File && pattern.test ( f.name ) && f.name!=".DS_Store" ) {
aFiles[ aFiles.length ] = f;
}
}
return aFiles;
}
else
{
return fo.getFiles ( filterFunction );
}
},
}
//Main routine
var main = function() {
var fo = Folder.selectDialog("Please select a folder"),
files, n = 0, doc, nFile,
opts = new EPSSaveOptions();
//Settings options
// opts.… = …
//Exit if no selected folder
if ( !fo ) return;
//getting AI files
files = api.getFiles ( fo, ["ai"], true );
n = files.length;
//Exit if no files found
if ( !n ) {
alert( "No files found sorry" );
return;
}
//convert found files
while ( n-- ) {
nFile = files
; doc = app.open ( files
); doc.saveAs ( File ( nFile.parent+"/"+nFile.name.replace ( /\.ai$/, '.eps' ) ), opts );
doc.close();
}
}
//run
main();
HTH
Copy link to clipboard
Copied
I've read tutorial after tutorial and can't seem to wrap my head around scripting for Illustrator. I'm looking to do just the opposite of what the OP wanted to do, I need to convert folders full of EPS files back to AI. If I were to switch those references around in the script you have provided would that work? If not, I don't want to bother you any further, just hoping it would be as easy as I'm speculating it to be.
Copy link to clipboard
Copied
You will have to change the save options to be the Illustrator ones (l.47) and the save-as file object to replace the eps with ai instead of how it is now (l.70).
Copy link to clipboard
Copied
sorry i wanna post a question about converting the eps to ai file , that i saw this post.can you help me for this?
Copy link to clipboard
Copied
Bonjou dr_rapide
Si tu veux faire l'inverse eps vers ai, tu remplaces la fin du script de Loïc à partir de la ligne 33
par
//Main routine ligne 33
var main = function() {
var fo = Folder.selectDialog("Please select a folder"),
files, n = 0, doc, nFile;
//Settings options
// Options pour l’enregistrement d’un document au format Illustrator.
var opts = new IllustratorSaveOptions();
// opts.… = …
//Exit if no selected folder
if ( !fo ) return;
//getting AI files
files = api.getFiles ( fo, ["eps"], true ); // alert(files)
n = files.length;
//Exit if no files found
if ( !n ) {
alert( "No files found sorry" );
return;
}
//convert found files
while ( n-- ) {
nFile = files[n];
doc = app.open ( files[n] );
doc.saveAs ( File ( nFile.parent+"/"+nFile.name.replace ( /\.eps$/, '.ai' ) ), opts );
doc.close();
}
}
//run
main();
restera si besoin à définir les options autres que par défaut
ligne //opts. ... = ....
de elleere
Copy link to clipboard
Copied
tnx a lot .
Copy link to clipboard
Copied
Hi Loic_Aigon,
Thanks for your answer! Would you mind explaining a line to me please?
!aFiles && aFiles =[];
This line causes my linter to complain. Is it functionally the same as writing:
if (!aFiles) aFiles = [];
Thanks,
Mark
Copy link to clipboard
Copied
Yes, that's correct,. If aFiles does not declared, it goes to the second condition after && and declared aFiles as an array.
Copy link to clipboard
Copied
👍
Copy link to clipboard
Copied
Hi I am trying to use this script again but no on CC2021. Getting an error.
Copy link to clipboard
Copied
I am also going from eps to ai now.
Copy link to clipboard
Copied
Bonjour,
Il faut inclure le début du script de Loïc placé avant
//Main routine ligne 33
Copy link to clipboard
Copied
//Some utils to retrieve files in folders and subfolders
var api = {
getFiles : function ( fo, aExtensions, bRecursive, aFiles, includeFolder )
{
var exts = aExtensions? aExtensions.join("|") : ".+" ;
var pattern = new RegExp ( "\\.("+exts+")$");
!aFiles && aFiles = [];
var filterFunction = function(file)
{
return pattern.test ( file.name );
}
if ( bRecursive && fo.name.indexOf ( ".")!=0 )
{
var foFiles = fo.getFiles();
while ( f = foFiles.shift() )
{
if ( f instanceof Folder )
{
if (includeFolder===true) files[ files.length ] = f;
this.getFiles ( f, aExtensions, true, aFiles );
}
if ( f instanceof File && pattern.test ( f.name ) && f.name!=".DS_Store" ) {
aFiles[ aFiles.length ] = f;
}
}
return aFiles;
}
else
{
return fo.getFiles ( filterFunction );
}
},
}
//Main routine
var main = function() {
var fo = Folder.selectDialog("Please select a folder"),
files, n = 0, doc, nFile,
opts = new EPSSaveOptions();
//Settings options
// opts.… = …
//Exit if no selected folder
if ( !fo ) return;
//getting AI files
files = api.getFiles ( fo, ["ai"], true );
n = files.length;
//Exit if no files found
if ( !n ) {
alert( "No files found sorry" );
return;
}
//convert found files
while ( n-- ) {
nFile = files;
doc = app.open ( files );
doc.saveAs ( File ( nFile.parent+"/"+nFile.name.replace ( /\.ai$/, '.eps' ) ), opts );
doc.close();
}
}
//run
main();
Copy link to clipboard
Copied
I am using this script to convert .ai to .eps files on the current version of CC and it has stopped working. Can anyone help? Please? Here is the erorr.
Copy link to clipboard
Copied
The text of the script has been slightly mangled, possibly by a forum re-vamp in the past. Here it is fixed up and tested on AI 2022 MacOS:
//Some utils to retrieve files in folders and subfolders
var api = {
getFiles: function (fo, aExtensions, bRecursive, aFiles, includeFolder) {
var exts = aExtensions ? aExtensions.join("|") : ".+";
var pattern = new RegExp("\\.(" + exts + ")$");
if (!aFiles) aFiles = [];
var filterFunction = function (file) {
return pattern.test(file.name);
}
if (bRecursive && fo.name.indexOf(".") != 0) {
var foFiles = fo.getFiles();
while (f = foFiles.shift()) {
if (f instanceof Folder) {
if (includeFolder === true) files[files.length] = f;
this.getFiles(f, aExtensions, true, aFiles);
}
if (f instanceof File && pattern.test(f.name) && f.name != ".DS_Store") {
aFiles[aFiles.length] = f;
}
}
return aFiles;
}
else {
return fo.getFiles(filterFunction);
}
},
}
//Main routine
var main = function () {
var fo = Folder.selectDialog("Please select a folder"),
files, n = 0, doc, nFile,
opts = new EPSSaveOptions();
//Settings options
// opts.… = …
//Exit if no selected folder
if (!fo) return;
//getting AI files
files = api.getFiles(fo, ["ai"], true);
n = files.length;
//Exit if no files found
if (!n) {
alert("No files found sorry");
return;
}
//convert found files
while (n--) {
nFile = files[n];
doc = app.open(nFile);
doc.saveAs(File(nFile.parent + "/" + nFile.name.replace(/\.ai$/, '.eps')), opts);
doc.close();
}
}
//run
main();
Copy link to clipboard
Copied
doesn't work
Error 8: Errore di sintassi.
Line: 1
> {\rtf1\ansi\ansicpg1252\cocoartf2636
Copy link to clipboard
Copied
@Jeansevilla, your error is because you have saved the script as a rich text file (see the "rtf1" tag in the error message). You must save the script as a plain text file.
- Mark
Copy link to clipboard
Copied
I am using this script to convert all EPS files, to AI.
The script works fine, I just want to:
1. when opening an error file the script continues to process the other files
2. when the MISSING FONT window appears, the window can be closed by itself and to put the conversion operation in AI (even without the font)
3. when it gives me the CMYK required notice go ahead
4. which can suppress any window that requires manual Acceptance by the user.
5. Do you know any other script maybe better than this one?
---------- [ CODE ] -----------------
//Some utils to retrieve files in folders and subfolders
var api = {
getFiles : function ( fo, aExtensions, bRecursive, aFiles, includeFolder )
{
var exts = aExtensions? aExtensions.join("|") : ".+" ;
var pattern = new RegExp ( "\\.("+exts+")$");
!aFiles && aFiles = [];
var filterFunction = function(file)
{
return pattern.test ( file.name );
}
if ( bRecursive && fo.name.indexOf ( ".")!=0 )
{
var foFiles = fo.getFiles();
while ( f = foFiles.shift() )
{
if ( f instanceof Folder )
{
if (includeFolder===true) files[ files.length ] = f;
this.getFiles ( f, aExtensions, true, aFiles );
}
if ( f instanceof File && pattern.test ( f.name ) && f.name!=".DS_Store" ) {
aFiles[ aFiles.length ] = f;
}
}
return aFiles;
}
else
{
return fo.getFiles ( filterFunction );
}
},
}
//Main routine
var main = function() {
var fo = Folder.selectDialog("Selezionare la cartella Sorgente! [eps, pdf, svg, ai ]"),
files, n = 0, doc, nFile,
opts = new IllustratorSaveOptions();
//Settings options
// opts.… = …
//Exit if no selected folder
if ( !fo ) return;
/////////// GETTING AI FILES //////////
//files = api.getFiles ( fo, ["eps", "ai", "pdf","svg"], true );
//files = api.getFiles ( fo, ["eps", "EPS", "ai", "AI"], true );
//files = api.getFiles ( fo, ["ai", "AI"], true );
files = api.getFiles ( fo, ["eps", "EPS"], true );
n = files.length;
//Exit if no files found
if ( !n ) {
alert( "Nessun file è stato trovato." );
return;
}
//convert found files
while ( n-- ) {
nFile = files[n];
doc = app.open ( nFile );
doc.saveAs ( File ( nFile.parent+"/"+nFile.name.replace ( /\.eps$/, '.ai' ) ), opts );
doc.close();
}
}
//run
main();
Copy link to clipboard
Copied
Hi
Can someone post a step-by-step guide on how to action the script on Macosx please? I am completely lost!