Wednesday, 4 April 2012

Illustrator - Automate export of objects to PNG files

Automate export of illustrator objects to individual PNG files.

Save the following script into a new js file.
Open you illustrator file, then goto File > Scripts > Other Scripts or hit F12


var msg =""
if(app.documents.length > 0)
{
var pgItems = app.activeDocument.pageItems;
tot_obj=pgItems.length ;
alert("Total Object are " + tot_obj);
if( pgItems.length > 0 )
{
  var msg = "Items are ";

  for( var i =0; i
  {
 
   pgItems[i].hidden =true;
   //msg   = pgItems[i].visible
  }
for( var i =0; i
  {
   pgItems[i].hidden =false;
   var exportOptions = new ExportOptionsPNG24();
   var type = ExportType.PNG24;
   var fileSpec = new File(i+"sample.png");
   exportOptions.antiAliasing = false;
   exportOptions.transparency = true;
   exportOptions.saveAsHTML = false;
   app.activeDocument.exportFile( fileSpec, type, exportOptions );
   pgItems[i].hidden =true;

  }
}
else
{
  msg = "No document Open";
}
alert(msg);
}

No comments: