Hi everyone.
I would like some help on this script I currently have if anyone is able to.
Basically, every image exported via this script is working fine, however the quality that it is exported into is much lower than that as you would export it manually via "File Export."
run_export: function() {
var num_exported = 0;
var options;
if ( this.format =='PNG 8' ) {
options = new ExportOptionsPNG8();
options.antiAliasing = true;
options.transparency = this.transparency;
options.artBoardClipping = true;
options.horizontalScale = this.scaling;
options.verticalScale = this.scaling;
} else if ( this.format == 'PNG 24' ) {
options = new ExportOptionsPNG24();
options.antiAliasing = true;
options.transparency = this.transparency;
options.artBoardClipping = true;
options.horizontalScale = this.scaling;
options.verticalScale = this.scaling;
} else if ( this.format == 'PDF' ) {
options = new PDFSaveOptions();
options.compatibility = PDFCompatibility.ACROBAT5;
options.generateThumbnails = true;
options.preserveEditability = false;
} else if ( this.format == 'JPG' ) {
options = new ExportOptionsJPEG();
options.antiAliasing = true;
options.artBoardClipping = true;
options.horizontalScale = this.scaling;
options.verticalScale = this.scaling;
} else if ( this.format == 'EPS' ) {
options = new EPSSaveOptions();
options.embedLinkedFiles = true;
options.includeDocumentThumbnails = true;
options.saveMultipleArtboards = true;
}
var starting_artboard = 0;
var num_artboards = aDoc.artboards.length;
if ( this.export_code == 'layers' ) {
starting_artboard = aDoc.artboards.getActiveArtboardIndex();
num_artboards = starting_artboard + 1;
}
for (var i = starting_artboard; i < num_artboards; i++ ) {
var artboardName = aDoc.artboards[i].name;
starting_artboard = aDoc.artboards.setActiveArtboardIndex(i);
// Process this artbarod if we're exporting only a single one (layers mode) or if it doesn't have generic name or minus
if ( this.export_code == 'layers' || ! ( artboardName.match( /^artboard/i ) || artboardName.match( /^\-/ ) )) {
// if exporting artboard by artboard, export layers as is
if ( this.export_code == 'artboards' ) {
var base_filename = this.base_path + "/" + this.prefix + artboardName + this.suffix
if ( this.format.match( /^PNG/ )) {
var destFile = new File( base_filename + '.png' );
var export_type = this.format == 'PNG 8' ? ExportType.PNG8 : ExportType.PNG24;
aDoc.exportFile(destFile, export_type , options);
} else if ( this.format.match( /^JPG/ )) {
var destFile = new File( base_filename + '.jpg' );
var export_type = ExportType.JPEG;
aDoc.exportFile(destFile, export_type , options);
} else if ( this.format.match( /^EPS/ )) {
// dumb. specify a filename, saveAs saves as something else
// so after we save it, we have to rename it to what we want.
var eps_real_filename = base_filename + '_' + artboardName + '.eps'
var destFile = new File( base_filename + '.eps' );
options.artboardRange = (i+1).toString();
aDoc.saveAs( destFile, options );
var epsFile = new File ( eps_real_filename );
if ( epsFile.exists ) {
epsFile.copy( base_filename + '.eps' );
epsFile.remove();
}
} else if ( this.format.match( /^PDF/ )) {
var destFile = new File( base_filename + '.pdf' );
options.artboardRange = (i+1).toString();
aDoc.saveAs( destFile, options )
}
// export layers as individual files
} else if ( this.export_code == 'layers' || this.export_code = 'both' ) {
for ( var j=0; j < aDoc.layers.length; j++ ) {
this.hide_all_layers();
var layer = aDoc.layers[j];
var lyr_name = layer.name;
if ( ! ( lyr_name.match( /^\+/ ) || lyr_name.match( /nyt_exporter_info/ ) || lyr_name.match( /^\-/) || lyr_name.match( /^Layer / ) )) {
var base_filename;
if ( this.export_code == 'layers' ) {
base_filename = this.base_path + "/" + this.prefix + lyr_name + this.suffix
} else if ( this.export_code == 'both' ) {
base_filename = this.base_path + "/" + this.prefix + artboardName + '-' + lyr_name + this.suffix
}
layer.visible = true;
if ( this.format.match( /^PNG/ )) {
var destFile = new File( base_filename + '.png' );
var export_type = this.format == 'PNG 8' ? ExportType.PNG8 : ExportType.PNG24;
aDoc.exportFile(destFile, export_type , options);
} else if ( this.format.match( /^JPG/ )) {
var destFile = new File( base_filename + '.jpg' );
var export_type = ExportType.JPEG;
aDoc.exportFile(destFile, export_type , options);
} else if ( this.format.match( /^EPS/ )) {
var eps_real_filename = base_filename + '_' + artboardName + '.eps'
var destFile = new File( base_filename + '.eps' );
options.artboardRange = (i+1).toString();
aDoc.saveAs( destFile, options )
var epsFile = new File ( eps_real_filename );
if ( epsFile.exists ) {
epsFile.copy( base_filename + '.eps' );
epsFile.remove();
}
} else if ( this.format.match( /^PDF/ )) {
var destFile = new File( base_filename + '.pdf' );
options.artboardRange = (i+1).toString();
aDoc.saveAs( destFile, options )
}
num_exported++;
this.dlg.progLabel.text = 'Exported ' + num_exported + ' of ' + this.num_to_export;
this.dlg.progBar.value = num_exported / this.num_to_export * 100;
this.dlg.update();
}
}
}
}
}
this.prefs_xml.nyt_base_path = this.base_path;
this.prefs_xml.nyt_scaling = this.scaling;
this.prefs_xml.nyt_prefix = this.prefix;
this.prefs_xml.nyt_suffix = this.suffix;
this.prefs_xml.nyt_transparency = this.transparency;
this.prefs_xml.nyt_format = this.format;
this.prefs_xml.nyt_export_code = this.export_code;
this.png_info_lyr.textFrames[0].contents = this.prefs_xml.toXMLString();
this.dlg.close();
//end run_export
},
hide_all_layers: function() {
var export_count = 0;
var n = aDoc.layers.length;
for(var i=0; i<n; ++i) {
layer = aDoc.layers[i];
lyr_name = layer.name;
// any layers that start with + are always turned on
if ( lyr_name.match( /^\+/ ) ) {
layer.visible = true;
// any layers that start with -, have default layer name, or named "nyt_exporter_info" are skipped
} else if ( lyr_name.match( /nyt_exporter_info/ ) || lyr_name.match( /^Layer /) || lyr_name.match( /^\-/ ) ){
layer.visible = false;
// everything else we should export
} else {
layer.visible = false;
export_count++;
}
}
return export_count;
},
get_num_layers_to_export: function() {
var num_to_export = 0;
var num_layers = aDoc.layers.length;
for(var i=0; i<num_layers; ++i) {
var layer = aDoc.layers[i];
var lyr_name = layer.name;
// any layers that start with + are always turned on
if ( lyr_name.match( /^\+/ ) ) {
} else if ( lyr_name.match( /nyt_exporter_info/ ) || lyr_name.match( /^Layer /) || lyr_name.match( /^\-/ ) ){
} else {
num_to_export++;
}
}
return num_to_export;
},
get_num_artboards_to_export: function() {
var num_artboards = aDoc.artboards.length;
var num_to_export = 0;
for (var i = 0; i < num_artboards; i++ ) {
var artboardName = aDoc.artboards[i].name;
if ( ! ( artboardName.match( /^artboard/i ) || artboardName.match( /^\-/ ) )){
num_to_export++;
}
}
return num_to_export;
},
show_all_layers: function() {
var n = aDoc.layers.length;
for(var i=0; i<n; ++i) {
layer = aDoc.layers[i];
layer.visible = true;
}
},
};
nyt_png_exporter.init();