• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Illustrator batch export to same folder

Contributor ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Have a folder containing several subfolders, each folder has a few EPS files. Ran a batch with an export script I created.

Works great except all files are being exported into one folder.

How do I get each to be saved into their respective folders, without interruption?

TOPICS
Scripting

Views

4.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Jun 07, 2017 Jun 07, 2017

here is the PNG

var Lib = { 

  getFiles : function ( fo, aExtensions, bRecursive, aFiles, includeFolder ) 

  { 

  var exts = aExtensions? aExtensions.join("|") : ".+" ; 

  var pattern = new RegExp ( "\\."+exts+"$", "g" ); 

  var files = aFiles? aFiles : []; 

  var filterFunction = function(file) 

  { 

  return pattern.test ( file.name ); 

  } 

 

  if ( bRecursive ) 

  { 

  var foFiles = fo.getFiles(); 

  while (  f = foFiles.shift() ) 

  { 

  if ( f instanceof Folder ) 

  { 

  if (includeFolder=

...

Votes

Translate

Translate
Adobe
People's Champ ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

File instances have a parent property that points to the folder where the file is located

var file = doc.fullName;

doc.save ( File ( file.parent+"/"+file.name.replace ( /\.ait?/i, "")+".pdf", … )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

Thank you Loic. Apologies, I misspoke -- it was an Action I had set up in Illustrator, not a Script. Is there anything I change in the Action or Batch preferences OR do I need to use/create a Script?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 24, 2017 May 24, 2017

Copy link to clipboard

Copied

Hi,

I think a script is better and not specifically hard to set:

var Lib = {

  getFiles : function ( fo, aExtensions, bRecursive, aFiles, includeFolder )

  {

  var exts = aExtensions? aExtensions.join("|") : ".+" ;

  var pattern = new RegExp ( "\\."+exts+"$", "g" );

  var files = aFiles? aFiles : [];

  var filterFunction = function(file)

  {

  return pattern.test ( file.name );

  }

  if ( bRecursive )

  {

  var foFiles = fo.getFiles();

  while (  f = foFiles.shift() )

  {

  if ( f instanceof Folder )

  {

  if (includeFolder===true) files[ files.length ] = f;

  this.getFiles ( f, aExtensions, true, files );

  }

  if ( f  instanceof File && pattern.test ( f.name ) && f.name!=".DS_Store" )

  files[ files.length ]  = f;

  }

  return files;

  }

  else

  {

  return fo.getFiles ( filterFunction );

  }

  },

  exportFile:function(file, opts) {

  var doc = app.open ( file ), data = {ok:true};

  try {

  doc.saveAs ( File ( file.parent+"/"+file.name.replace ( /\.eps?$/i, "" )+".pdf" ), opts);

  }

  catch(err) {

  data.ok = false;

  data.message = "âš  "+file.name+" couldn't exported cause :"+err.message ;

  }

  doc.close ( SaveOptions.DONOTSAVECHANGES );

  return data;

  },

  log:function(msg) {

  var f = File ( Folder.desktop+"/batchExport.txt" );

  f.open('a');

  f.writeln ( msg );

  f.close();

  },

  getPDFOpts:function() {

  var opts = new PDFSaveOptions();

  opts.preserveEditability = true;

  //whatever options you may want to set here

  return opts;

  }

}

var main = function() {

  var fo = Folder.selectDialog("Please choose a folder"),

  files,n = 0,

  uip, result, pdfOpts, errors = [];

  if ( !fo ) return;

  files = Lib.getFiles ( fo, ["eps"], true );

  n = files.length;

  if ( !n ) {

  alert("No files could be found");

  return;

  }

  pdfOpts = Lib.getPDFOpts();

  uip = app.userInteractionLevel;

  app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

  while (n--) {

  result = Lib.exportFile ( files, pdfOpts );

  !result.ok && errors.push ( result.message );

  }

  app.userInteractionLevel = uip;

  errors.length && Lib.log ( errors.join("\r") );

  alert( errors.length? "Some errors occured. Check log on Desktop" : "Everything worked smoothly" );

}

main();

HTH

Loic

Ozalto | Productivity Oriented - Loïc Aigon

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 26, 2017 May 26, 2017

Copy link to clipboard

Copied

Your script for PDF export works great Loic. I will try to update it for PNG export. Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 24, 2017 May 24, 2017

Copy link to clipboard

Copied

If you want to keep your batch action export in the exact folders where they are picked from, why not just select "Save and Close" as the option for 'destination'?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 24, 2017 May 24, 2017

Copy link to clipboard

Copied

Thank you Silly, and Loic for the great script. Silly, yes I did try that initially...

It seems the issue lies in my Action. The Action recorded/remembers the designation folder when I created it. After reading other's posts about this issue I see there isn't an easy way around this in Illustrator. I'm new at this so pardon my ignorance.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 31, 2017 May 31, 2017

Copy link to clipboard

Copied

Try an experiment if you can: when you export a copy (or save) the file with an action, make sure not to change the default file name provided.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 31, 2017 May 31, 2017

Copy link to clipboard

Copied

IIRC an action saves an absolute path to the location that you originally saved to when you created the action. I don't believe it's able to make a reference to a relative folder path.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 31, 2017 May 31, 2017

Copy link to clipboard

Copied

Yes William, that's what I'm finding with Illustrator.

Photoshop, on the other hand, works great. Created my export PNG Action then ran Batch w Include All Subfolders / Suppress File Open Dialogs / Destination: Save and Close / Override Save As.

So I'll use Photoshop or find a script to run in Illustrator (not having much luck tweaking above script)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 31, 2017 May 31, 2017

Copy link to clipboard

Copied

I wanna do a test for my own knowledge on this when I get a chance.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 31, 2017 May 31, 2017

Copy link to clipboard

Copied

By all means have a go. Perhaps you'll see something i didn't. But it seems pretty clear to me. I just did a quick test and the result was what i expected. Also when you look at the action in the actions panel, under the Save As 'command', it shows the absolute path to wherever the file was saved to when the action was created.

My original thought was "well duh, that's because you used save as". But of course, that's the only way you could do it. You can't do a simple "save" because then what would be the point of creating an action that just saves a file without changing it's filetype etc.

I got the same result when creating an action that exports something into it's existing folder.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 01, 2017 Jun 01, 2017

Copy link to clipboard

Copied

I thought that "Save and Close" would do this, if we are starting with EPS files in a folder tree and the result is to just process those files, each one should be overwritten.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2017 Jun 01, 2017

Copy link to clipboard

Copied

Oh, i certainly could have mis-read the original post. I thought that a "save as eps" was part of the thing. i guess i don't know what the action is doing.

Certainly if there's no save command in the action, save and close will save the file right back into it's location just as you said.

Words are hard. Misunderstandings abound. Shame permeates.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 01, 2017 Jun 01, 2017

Copy link to clipboard

Copied

No shame. I'm exporting existing EPS files as transparent PNGs (1 main folder with many sub folders). Alas, the recorded Action remembers the original designation as recorded.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2017 Jun 01, 2017

Copy link to clipboard

Copied

Yea.. a script is going to have to be the way to go then.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 01, 2017 Jun 01, 2017

Copy link to clipboard

Copied

Oh, no, I think it was I who had misunderstood the situation. The objective is to export different files out of the EPS files, which are not EPS then.

Yea a script would be useful, but I am trying to think of how to make a nice generic script which can be played within the action..., and I am thinking that a script would be better than the batch process since you can play a script with an action, but I heard that it crashes when you try to play an action from a script that's already being played by an action. Lol

I'm now thinking for a less hard-coded way to give the user the export process, such as providing a saved action file instruction - the script could use those actions and replace the destination folder string inside, but keep all the user preferences.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jun 01, 2017 Jun 01, 2017

Copy link to clipboard

Copied

miss-charlotte​ settings svg as export format isn't  a big deal. Will provide a fix when i come back at the offic.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 01, 2017 Jun 01, 2017

Copy link to clipboard

Copied

Loic, that would be great! Your PDF script above worked well. If it could be tweaked to export transparent, 300 ppi, PNG that would be great. I don't need them to open up/launch at the end.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jun 07, 2017 Jun 07, 2017

Copy link to clipboard

Copied

here is the PNG

var Lib = { 

  getFiles : function ( fo, aExtensions, bRecursive, aFiles, includeFolder ) 

  { 

  var exts = aExtensions? aExtensions.join("|") : ".+" ; 

  var pattern = new RegExp ( "\\."+exts+"$", "g" ); 

  var files = aFiles? aFiles : []; 

  var filterFunction = function(file) 

  { 

  return pattern.test ( file.name ); 

  } 

 

  if ( bRecursive ) 

  { 

  var foFiles = fo.getFiles(); 

  while (  f = foFiles.shift() ) 

  { 

  if ( f instanceof Folder ) 

  { 

  if (includeFolder===true) files[ files.length ] = f; 

 

  this.getFiles ( f, aExtensions, true, files ); 

  } 

  if ( f  instanceof File && pattern.test ( f.name ) && f.name!=".DS_Store" )  

  files[ files.length ]  = f; 

  } 

 

  return files; 

  } 

 

  else 

  { 

  return fo.getFiles ( filterFunction ); 

  } 

  }, 

 

  exportFile:function(file, opts, pngOpts) { 

 

  var doc = app.open ( file ), data = {ok:true}; 

 

 

  try { 

  //doc.saveAs ( File ( file.parent+"/"+file.name.replace ( /\.eps?$/i, "" )+".pdf" ), opts); 

  doc.exportFile( File ( file.parent+"/"+file.name.replace ( /\.eps?$/i, "" )+".png" ), ExportType.PNG24, pngOpts );

  } 

  catch(err) { 

  data.ok = false; 

  data.message = "âš  "+file.name+" couldn't exported cause :"+err.message ; 

  } 

  doc.close ( SaveOptions.DONOTSAVECHANGES ); 

 

  return data; 

  }, 

 

 

  log:function(msg) { 

  var f = File ( Folder.desktop+"/batchExport.txt" ); 

  f.open('a'); 

  f.writeln ( msg ); 

  f.close(); 

  }, 

 

  getPNGOpts:function() {

  var opts = new ExportOptionsPNG24();

  opts.antiAliasing = true;

  opts.transparency = true;

  return opts;

},

 

  getPDFOpts:function() { 

  var opts = new PDFSaveOptions(); 

  opts.preserveEditability = true; 

  //whatever options you may want to set here 

 

  return opts; 

  } 

 

 

var main = function() { 

  var fo = Folder.selectDialog("Please choose a folder"), 

  files,n = 0, 

  uip, result, pdfOpts, errors = [],

  pngOpts;

 

  if ( !fo ) return; 

 

  files = Lib.getFiles ( fo, ["eps"], true ); 

 

  n = files.length; 

 

  if ( !n ) { 

  alert("No files could be found"); 

  return; 

  } 

 

  pdfOpts = Lib.getPDFOpts(); 

  pngOpts = Lib.getPNGOpts();

 

  uip = app.userInteractionLevel; 

  app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; 

 

  while (n--) { 

  result = Lib.exportFile ( files, pdfOpts, pngOpts ); 

  !result.ok && errors.push ( result.message ); 

  } 

 

 

  app.userInteractionLevel = uip; 

  errors.length && Lib.log ( errors.join("\r") ); 

  alert( errors.length? "Some errors occured. Check log on Desktop" : "Everything worked smoothly" ); 

 

 

 

main();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 07, 2017 Jun 07, 2017

Copy link to clipboard

Copied

Fabulous! Works great. Good Karma coming your way Loic.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 27, 2018 Feb 27, 2018

Copy link to clipboard

Copied

LATEST

FANTASTIC!!!!

Thanks a lot Loic.Aigon​, you saved my day!!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines