case PDFEncoding.PDFZIP:
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.rbZip.value = true; break;
case PDFEncoding.JPEG:
default:
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.rbJpeg.value = true; break;
}
if (PDFEncoding.JPEG != exportInfo.pdfEncoding) {
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.stQuality.enabled = false;
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.etQuality.enabled = false;
}
// Targa options
dlgMain.pnlFileType.pnlOptions.grpTargaOptions = dlgMain.pnlFileType.pnlOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpTargaOptions.add("statictext", undefined, strLabelDepth);
dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb16bit = dlgMain.pnlFileType.pnlOptions.grpTargaOptions.add( "radiobutton", undefined, strRadiobutton16bit);
dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb24bit = dlgMain.pnlFileType.pnlOptions.grpTargaOptions.add( "radiobutton", undefined, strRadiobutton24bit);
dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb32bit = dlgMain.pnlFileType.pnlOptions.grpTargaOptions.add( "radiobutton", undefined, strRadiobutton32bit);
switch (exportInfo.targaDepth) {
case TargaBitsPerPixels.SIXTEEN: dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb16bit.value = true; break;
case TargaBitsPerPixels.TWENTYFOUR: dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb24bit.value = true; break;
case TargaBitsPerPixels.THIRTYTWO: dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb32bit.value = true; break;
default: dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb24bit.value = true; break;
}
// BMP options
dlgMain.pnlFileType.pnlOptions.grpBMPOptions = dlgMain.pnlFileType.pnlOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpBMPOptions.add("statictext", undefined, strLabelDepth);
dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb16bit = dlgMain.pnlFileType.pnlOptions.grpBMPOptions.add( "radiobutton", undefined, strRadiobutton16bit);
dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb24bit = dlgMain.pnlFileType.pnlOptions.grpBMPOptions.add( "radiobutton", undefined, strRadiobutton24bit);
dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb32bit = dlgMain.pnlFileType.pnlOptions.grpBMPOptions.add( "radiobutton", undefined, strRadiobutton32bit);
switch (exportInfo.bmpDepth) {
case BMPDepthType.SIXTEEN: dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb16bit.value = true; break;
case BMPDepthType.TWENTYFOUR:dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb24bit.value = true; break;
case BMPDepthType.THIRTYTWO: dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb32bit.value = true; break;
default: dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb24bit.value = true; break;
}
// the right side of the dialog, the ok and cancel buttons
dlgMain.grpTopRight = dlgMain.grpTop.add("group");
dlgMain.grpTopRight.orientation = 'column';
dlgMain.grpTopRight.alignChildren = 'fill';
dlgMain.btnRun = dlgMain.grpTopRight.add("button", undefined, strButtonRun );
dlgMain.btnRun.onClick = function() {
// check if the setting is properly
var destination = dlgMain.etDestination.text;
if (destination.length == 0) {
alert(strAlertSpecifyDestination);
return;
}
var testFolder = new Folder(destination);
if (!testFolder.exists) {
alert(strAlertDestinationNotExist);
return;
}
dlgMain.close(runButtonID);
}
dlgMain.btnCancel = dlgMain.grpTopRight.add("button", undefined, strButtonCancel );
dlgMain.btnCancel.onClick = function() {
dlgMain.close(cancelButtonID);
}
dlgMain.defaultElement = dlgMain.btnRun;
dlgMain.cancelElement = dlgMain.btnCancel;
// the bottom of the dialog
dlgMain.grpBottom = dlgMain.add("group");
dlgMain.grpBottom.orientation = 'column';
dlgMain.grpBottom.alignChildren = 'left';
dlgMain.grpBottom.alignment = 'fill';
dlgMain.pnlHelp = dlgMain.grpBottom.add("panel");
dlgMain.pnlHelp.alignment = 'fill';
dlgMain.etHelp = dlgMain.pnlHelp.add("statictext", undefined, strHelpText, {multiline:true});
dlgMain.etHelp.alignment = 'fill';
dlgMain.onShow = function() {
dlgMain.ddFileType.onChange();
}
// give the hosting app the focus before showing the dialog
app.bringToFront();
dlgMain.center();
var result = dlgMain.show();
if (cancelButtonID == result) {
return result; // close to quit
}
// get setting from dialog
exportInfo.destination = dlgMain.etDestination.text;
exportInfo.fileNamePrefix = dlgMain.etFileNamePrefix.text;
exportInfo.visibleOnly = dlgMain.cbVisible.value;
exportInfo.fileType = dlgMain.ddFileType.selection.index;
exportInfo.icc = dlgMain.cbIcc.value;
exportInfo.jpegQuality = dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.etQuality.text;
exportInfo.psdMaxComp = dlgMain.pnlFileType.pnlOptions.grpPSDOptions.cbMax.value;
index = dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression.ddCompression.selection.index;
if (index == compNoneIndex) {
exportInfo.tiffCompression = TIFFEncoding.NONE;
}
if (index == compLZWIndex) {
exportInfo.tiffCompression = TIFFEncoding.TIFFLZW;
}
if (index == compZIPIndex) {
exportInfo.tiffCompression = TIFFEncoding.TIFFZIP;
}
if (index == compJPEGIndex) {
exportInfo.tiffCompression = TIFFEncoding.JPEG;
}
exportInfo.tiffJpegQuality = dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.etQuality.text;
if (dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.rbZip.value) {
exportInfo.pdfEncoding = PDFEncoding.PDFZIP;
}
if (dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.rbJpeg.value) {
exportInfo.pdfEncoding = PDFEncoding.JPEG;
}
exportInfo.pdfJpegQuality = dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.etQuality.text;
if (dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb16bit.value) {
exportInfo.targaDepth = TargaBitsPerPixels.SIXTEEN;
}
if (dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb24bit.value) {
exportInfo.targaDepth = TargaBitsPerPixels.TWENTYFOUR;
}
if (dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb32bit.value) {
exportInfo.targaDepth = TargaBitsPerPixels.THIRTYTWO;
}
if (dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb16bit.value) {
exportInfo.bmpDepth = BMPDepthType.SIXTEEN;
}
if (dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb24bit.value) {
exportInfo.bmpDepth = BMPDepthType.TWENTYFOUR;
}
if (dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb32bit.value) {
exportInfo.bmpDepth = BMPDepthType.THIRTYTWO;
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
// Function: hideAllFileTypePanel
// Usage: hide all the panels in the common actions
// Input: <none>, dlgMain is a global for this script
// Return: <none>, all panels are now hidden
///////////////////////////////////////////////////////////////////////////////
function hideAllFileTypePanel() {
dlgMain.pnlFileType.pnlOptions.grpPSDOptions.hide();
dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.hide();
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.hide();
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.hide();
dlgMain.pnlFileType.pnlOptions.grpTargaOptions.hide();
dlgMain.pnlFileType.pnlOptions.grpBMPOptions.hide();
dlgMain.pnlFileType.pnlOptions.grpPNG8Options.hide();
dlgMain.pnlFileType.pnlOptions.grpGIFOptions.hide();
dlgMain.pnlFileType.pnlOptions.grpPNG24Options.hide();
}
///////////////////////////////////////////////////////////////////////////////
// Function: initExportInfo
// Usage: create our default parameters
// Input: a new Object
// Return: a new object with params set to default
///////////////////////////////////////////////////////////////////////////////
function initExportInfo(exportInfo) {
exportInfo.destination = new String("");
exportInfo.fileNamePrefix = new String("untitled_");
exportInfo.visibleOnly = false;
exportInfo.fileType = psdIndex;
exportInfo.icc = true;
exportInfo.jpegQuality = 8;
exportInfo.psdMaxComp = true;
exportInfo.tiffCompression = TIFFEncoding.NONE;
exportInfo.tiffJpegQuality = 8;
exportInfo.pdfEncoding = PDFEncoding.JPEG;
exportInfo.pdfJpegQuality = 8;
exportInfo.targaDepth = TargaBitsPerPixels.TWENTYFOUR;
exportInfo.bmpDepth = BMPDepthType.TWENTYFOUR;
exportInfo.png24Transparency = true;
exportInfo.png24Interlaced = false;
exportInfo.gifTransparency = false;
exportInfo.gifInterlaced = false;
exportInfo.png24Trim = true;
exportInfo.gifTrim = false;
exportInfo.png8Transparency = true;
exportInfo.png8Interlaced = false;
exportInfo.png8Trim = true;
try {
exportInfo.destination = Folder(app.activeDocument.fullName.parent).fsName; // destination folder
var tmp = app.activeDocument.fullName.name;
exportInfo.fileNamePrefix = decodeURI(tmp.substring(0, tmp.indexOf("."))); // filename body part
} catch(someError) {
exportInfo.destination = new String("");
exportInfo.fileNamePrefix = app.activeDocument.name; // filename body part
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: saveFile
// Usage: the worker routine, take our params and save the file accordingly
// Input: reference to the document, the name of the output file,
// export info object containing more information
// Return: <none>, a file on disk
///////////////////////////////////////////////////////////////////////////////
function saveFile( docRef, fileNameBody, exportInfo) {
switch (exportInfo.fileType) {
case jpegIndex:
docRef.bitsPerChannel = BitsPerChannelType.EIGHT;
var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".jpg");
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = exportInfo.icc;
jpgSaveOptions.quality = exportInfo.jpegQuality;
docRef.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
break;
case psdIndex:
var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".psd");
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = exportInfo.icc;
psdSaveOptions.maximizeCompatibility = exportInfo.psdMaxComp;
docRef.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
break;
case tiffIndex:
var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".tif");
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = exportInfo.icc;
tiffSaveOptions.imageCompression = exportInfo.tiffCompression;
if (TIFFEncoding.JPEG == exportInfo.tiffCompression) {
tiffSaveOptions.jpegQuality = exportInfo.tiffJpegQuality;
}
docRef.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
break;
case gifIndex:
var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".gif");
gifSaveOptions = new GIFSaveOptions();
gifSaveOptions.embedColorProfile = exportInfo.icc;
gifSaveOptions.imageCompression = exportInfo.gifCompression;
if (GIFEncoding.JPEG == exportInfo.gifCompression) {
gifSaveOptions.jpegQuality = exportInfo.gifJpegQuality;
}
docRef.saveAs(saveFile, gifSaveOptions, true, Extension.LOWERCASE);
break;
case pdfIndex:
if (docRef.bitsPerChannel == BitsPerChannelType.THIRTYTWO)
docRef.bitsPerChannel = BitsPerChannelType.SIXTEEN;
var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".pdf");
pdfSaveOptions = new PDFSaveOptions();
pdfSaveOptions.embedColorProfile = exportInfo.icc;
pdfSaveOptions.encoding = exportInfo.pdfEncoding;
if (PDFEncoding.JPEG == exportInfo.pdfEncoding) {
pdfSaveOptions.jpegQuality = exportInfo.pdfJpegQuality;
}
docRef.saveAs(saveFile, pdfSaveOptions, true, Extension.LOWERCASE);
break;
case targaIndex:
docRef.bitsPerChannel = BitsPerChannelType.EIGHT;
var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".tga");
targaSaveOptions = new TargaSaveOptions();
targaSaveOptions.resolution = exportInfo.targaDepth;
docRef.saveAs(saveFile, targaSaveOptions, true, Extension.LOWERCASE);
break;
case bmpIndex:
docRef.bitsPerChannel = BitsPerChannelType.EIGHT;
var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".bmp");
bmpSaveOptions = new BMPSaveOptions();
bmpSaveOptions.depth = exportInfo.bmpDepth;
docRef.saveAs(saveFile, bmpSaveOptions, true, Extension.LOWERCASE);
break;
case png8Index:
saveFile(docRef, fileNameBody, exportInfo, dlgMain.pnlFileType.pnlOptions.grpPNG24Options.png24Inter.value, dlgMain.pnlFileType.pnlOptions.grpPNG24Options.png24Trans.value);
function saveFile( docRef, fileNameBody, exportInfo, interlacedValue, transparencyValue) {
var id5 = charIDToTypeID( "Expr" );
var desc3 = new ActionDescriptor();
var id6 = charIDToTypeID( "Usng" );
var desc4 = new ActionDescriptor();
var id7 = charIDToTypeID( "Op " );
var id8 = charIDToTypeID( "SWOp" );
var id9 = charIDToTypeID( "OpSa" );
desc4.putEnumerated( id7, id8, id9 );
var id10 = charIDToTypeID( "Fmt " );
var id11 = charIDToTypeID( "IRFm" );
var id12 = charIDToTypeID( "PNG8" );
desc4.putEnumerated( id10, id11, id12 );
var id13 = charIDToTypeID( "Intr" ); //Interlaced
desc4.putBoolean( id13, interlacedValue );
var id14 = charIDToTypeID( "RedA" );
var id15 = charIDToTypeID( "IRRd" );
var id16 = charIDToTypeID( "Prcp" ); //Algorithm
desc4.putEnumerated( id14, id15, id16 );
var id17 = charIDToTypeID( "RChT" );
desc4.putBoolean( id17, false );
var id18 = charIDToTypeID( "RChV" );
desc4.putBoolean( id18, false );
var id19 = charIDToTypeID( "AuRd" );
desc4.putBoolean( id19, false );
var id20 = charIDToTypeID( "NCol" ); //NO. Of Colors
desc4.putInteger( id20, 256 );
var id21 = charIDToTypeID( "Dthr" ); //Dither
var id22 = charIDToTypeID( "IRDt" );
var id23 = charIDToTypeID( "Dfsn" ); //Dither type
desc4.putEnumerated( id21, id22, id23 );
var id24 = charIDToTypeID( "DthA" );
desc4.putInteger( id24, 100 );
var id25 = charIDToTypeID( "DChS" );
desc4.putInteger( id25, 0 );
var id26 = charIDToTypeID( "DCUI" );
desc4.putInteger( id26, 0 );
var id27 = charIDToTypeID( "DChT" );
desc4.putBoolean( id27, false );
var id28 = charIDToTypeID( "DChV" );
desc4.putBoolean( id28, false );
var id29 = charIDToTypeID( "WebS" );
desc4.putInteger( id29, 0 );
var id30 = charIDToTypeID( "TDth" ); //transparency dither
var id31 = charIDToTypeID( "IRDt" );
var id32 = charIDToTypeID( "None" );
desc4.putEnumerated( id30, id31, id32 );
var id33 = charIDToTypeID( "TDtA" );
desc4.putInteger( id33, 100 );
var id34 = charIDToTypeID( "Trns" ); //Transparency
desc4.putBoolean( id34, transparencyValue );
var id35 = charIDToTypeID( "Mtt " );
desc4.putBoolean( id35, true ); //matte
var id36 = charIDToTypeID( "MttR" ); //matte color
desc4.putInteger( id36, 255 );
var id37 = charIDToTypeID( "MttG" );
desc4.putInteger( id37, 255 );
var id38 = charIDToTypeID( "MttB" );
desc4.putInteger( id38, 255 );
var id39 = charIDToTypeID( "SHTM" );
desc4.putBoolean( id39, false );
var id40 = charIDToTypeID( "SImg" );
desc4.putBoolean( id40, true );
var id41 = charIDToTypeID( "SSSO" );
desc4.putBoolean( id41, false );
var id42 = charIDToTypeID( "SSLt" );
var list1 = new ActionList();
desc4.putList( id42, list1 );
var id43 = charIDToTypeID( "DIDr" );
desc4.putBoolean( id43, false );
var id44 = charIDToTypeID( "In " );
desc4.putPath( id44, new File( exportInfo.destination + "/" + fileNameBody + ".png") );
var id45 = stringIDToTypeID( "SaveForWeb" );
desc3.putObject( id6, id45, desc4 );
executeAction( id5, desc3, DialogModes.NO );
}
//var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".png");
//bmpSaveOptions = new BMPSaveOptions();
//bmpSaveOptions.depth = exportInfo.bmpDepth;
//docRef.saveAs(saveFile, bmpSaveOptions, true, Extension.LOWERCASE);
break;
break;
case png24Index:
saveFile(docRef, fileNameBody, exportInfo, dlgMain.pnlFileType.pnlOptions.grpPNG24Options.png24Inter.value, dlgMain.pnlFileType.pnlOptions.grpPNG24Options.png24Trans.value);
function saveFile( docRef, fileNameBody, exportInfo, interlacedValue, transparencyValue) {
var id6 = charIDToTypeID( "Expr" );
var desc3 = new ActionDescriptor();
var id7 = charIDToTypeID( "Usng" );
var desc4 = new ActionDescriptor();
var id8 = charIDToTypeID( "Op " );
var id9 = charIDToTypeID( "SWOp" );
var id10 = charIDToTypeID( "OpSa" );
desc4.putEnumerated( id8, id9, id10 );
var id11 = charIDToTypeID( "Fmt " );
var id12 = charIDToTypeID( "IRFm" );
var id13 = charIDToTypeID( "PN24" );
desc4.putEnumerated( id11, id12, id13 );
var id14 = charIDToTypeID( "Intr" );
desc4.putBoolean( id14, interlacedValue );
var id15 = charIDToTypeID( "Trns" );
desc4.putBoolean( id15, transparencyValue );
var id16 = charIDToTypeID( "Mtt " );
desc4.putBoolean( id16, true );
var id17 = charIDToTypeID( "MttR" );
desc4.putInteger( id17, 255 );
var id18 = charIDToTypeID( "MttG" );
desc4.putInteger( id18, 255 );
var id19 = charIDToTypeID( "MttB" );
desc4.putInteger( id19, 255 );
var id20 = charIDToTypeID( "SHTM" );
desc4.putBoolean( id20, false );
var id21 = charIDToTypeID( "SImg" );
desc4.putBoolean( id21, true );
var id22 = charIDToTypeID( "SSSO" );
This post was edited by phuckina on Mar 31 2010 09:28am