- Сообщения
- 12
- Реакции
- 0
Здравствуйте, знающие люди, помогите подправить скрипт, что бы экспортировалась каждая монтажная область в отдельный файл...т.е. из трех допустим, артбордов получилось на выходе 3 EPS и 3jpeg файла...а не один где все вместе...вот код:
Код:
var Doc;
var fileType, targetFile, targetFile1, jpgExportOpts, epsSaveOpts;
var Name;
var name1;
var pathName;
var destFolder;
var width, height;
var statusMsg="\n";
if (app.documents.length==0)
{
alert("There are no documents opened. Nothing has been done.");
}else{
Doc=activeDocument;
Doc.save();
Name=Doc.name;
// get size of the image in pixels
width=Doc.visibleBounds[2]-Doc.visibleBounds[0];
height=Doc.visibleBounds[1]-Doc.visibleBounds[3];
// check if the filename has extension
if (Name.indexOf('.') < 0) {
name1 = Name;
} else {
var token = Name.lastIndexOf('.');
name1 = Name.substring(0, token);
}
pathName=Doc.fullName+" "; // convert pathName to string. Otherwise lastIndexOf does not work
token = pathName.lastIndexOf('/');
destFolder = pathName.substring(0, token);
///////////////////////////////////////////////////////
//
// Export JPGs
//
///////////////////////////////////////////////////////
fileType = ExportType.JPEG;
// Call function getJPGOptions get the ExportOptionsJPEG for the files
if (jpgExportOpts = getJPGOptions(4000, width, height ))
{
// Export as a big jpg
targetFile = new File(destFolder + '/' + name1 + '-Ai10');
Doc.exportFile( targetFile, fileType, jpgExportOpts );
statusMsg+="4000 px JPG\t...\tOK\n"
}else{
statusMsg+="4000 px JPG\t...\tFailed\n"
}
///////////////////////////////////////////////////////
//
// Save as EPS
//
///////////////////////////////////////////////////////
// Call function getESPOptions get the EPSSaveOptions for the files
epsSaveOpts = getEPSOptions("10");
targetFile = new File(destFolder + '/' + name1 + "-Ai10.eps");
Doc.saveAs(targetFile, epsSaveOpts);
statusMsg+="EPS Ai10\t\t...\tOK\n"
// Now EPS file is active. Reopen Ai file
Doc.close();
targetFile1 = new File(destFolder + '/' + name1 + ".ai");
Doc=app.open(targetFile1);
statusMsg+="\nFor updates subscribe: http://oksancia.com/feed"
alert( 'SaveForStocks-10\nThe following files were saved to:\n' + destFolder +'\n' + statusMsg);
}
/*********************************************************
getEPSOptions: Function to set the EPS saving options of the
files using the EPSSaveOptions object.
**********************************************************/
function getEPSOptions(compatibility)
{
// Create the EPSSaveOptions object to set the PDF options
var epsSaveOpts = new EPSSaveOptions();
// Setting EPSSaveOptions properties. Please see the JavaScript Reference
// for a description of these properties.
if (compatibility=="10") {
epsSaveOpts.compatibility= Compatibility.ILLUSTRATOR10;
}else{
epsSaveOpts.compatibility= Compatibility.ILLUSTRATOR8;
}
epsSaveOpts.includeDocumentThumbnails = true;
epsSaveOpts.postScript = EPSPostScriptLevelEnum.LEVEL2;
epsSaveOpts.preview = EPSPreview.COLORTIFF; //default
return epsSaveOpts;
}
/*********************************************************
getJPGOptions: Function to set the JPG saving options of the
files using the EPSSaveOptions object.
**********************************************************/
function getJPGOptions(maxSize,width,height)
{
var scaling;
// Create the ExportOptionsJPEG object to set the JPG options
var jpgExportOpts = new ExportOptionsJPEG();
// Setting ExportOptionsJPEG properties. Please see the JavaScript Reference
// for a description of these properties.
jpgExportOpts.antiAliasing = true;
jpgExportOpts.optimization = true;
jpgExportOpts.qualitySetting = 100
jpgExportOptions.artBoardClipping = true;;
if (width>height)
{
scaling=maxSize/width * 100;
}else{
scaling=maxSize/height *100;
}
if (scaling>776.19)
{
var needed=Math.round(scaling/776.19*10)/10;
alert ("Warning!\n\nThe image is too small and due to the Illustrator limitations could not be resized to " + maxSize + "px.\n"+ "Please scale the image by at least " + needed + " times.");
return 0;
}
jpgExportOpts.horizontalScale = scaling;
jpgExportOpts.verticalScale = scaling;
return jpgExportOpts;
}