How do I create an export batch script in Illustrator CS4?
How do I create a batch script that would export a set of AI files in CS4 to a png of a certain size?
Solution 1:
You should have a scripts folder somewhere like this: C:\Program Files\Adobe\Adobe Illustrator CS2\Presets\Scripts
. Copy the ExportDocsAsFlash.js
to ExportDocsAsPNG24.js
and modify using the AI Javascript Reference as a guide.
I tried this w/ CS2 (code below), but there seems to be a bug in the engine. For PNG's (and GIF's it seems) it doesn't access subsequent document objects so it saves the same document each time. Hopefully CS4 has this patched.
var j, sourceDoc, targetFile;
var destFolder = null;
// Get the destination to save the files
destFolder = Folder.selectDialog( 'Select the folder where you want to save the exported files.', '~' );
if (destFolder != null) {
for ( j = 0; j < app.documents.length; j++ ) {
sourceDoc = app.documents[ j ]; // returns the document object
targetFile = getNewName(sourceDoc, destFolder);
// set PNG export options
var opt = new ExportOptionsPNG24();
opt.antiAliasing = true;
opt.transparency = true;
// Export
sourceDoc.exportFile(targetFile, ExportType.PNG24, opt);
}
alert( 'Files are saved as PNG24 in ' + destFolder );
}
function getNewName(sourceDoc, destFolder) {
var docName = sourceDoc.name;
var ext = '.png'; // new extension for png file
var newName = "";
// if name has no dot (and hence no extension,
// just append the extension
if (docName.indexOf('.') < 0) {
newName = docName + ext;
} else {
var dot = docName.lastIndexOf('.');
newName += docName.substring(0, dot);
newName += ext;
}
// Create a file object to save the png
saveInFile = new File( destFolder + '/' + newName );
return saveInFile;
}
Solution 2:
You can do it with inkscape's export option.
First install inkscape:
apt-get install inkscape
Create an export_to_png.sh
script with the following code:
#!/bin/bash
for i in $(ls $1);
do
inkscape -w100 -h100 -e $1/$i.png $1/$i
done
Make it executable:
chmod +x export_to_png.sh
Then run it:
./export_to_png.sh /path/to/images/
It will convert "somefile.ai" to "somefile.ai.png" with 100x100 size.