Home » Questions » Computers [ Ask a new question ]

How do I create an export batch script in Illustrator CS4?

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?

Asked by: Guest | Views: 309
Total answers/comments: 1
bert [Entry]

"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;
}"