cancel button(function) not woking
Copy link to clipboard
Copied
Hi all,
Here is my script for export pdf for selecting preset, it is working, but not working to cancel the action, still exporting PDF for canceling action
what's the bug, any one can help me?
var mydoc = app.documents.item(0);
var myPresets = app.pdfExportPresets.everyItem().name;
myPresets.unshift("- Select Preset - ");
var myWin = new Window('dialog', 'PDF Export Presets');
myWin.orientation = 'row';
with(myWin){
myWin.sText = add('statictext', undefined, '');
myWin.myPDFExport = add('dropdownlist',undefined,undefined,{items:myPresets});
myWin.myPDFExport.selection = ("items:myPresets");
myWin.btnOK = add('button', undefined, 'OK');
myWin.btnCancel = add('button', undefined, 'Cancel');
};
myWin.center();
var myWindow = myWin.show();
var myOutFolderPathName = "/Users/Desktop/Watched Folder/Out/"; //Please change your path as per requirement
var myPDFFilePath;
myPreset = myWin.myPDFExport.selection.index;
var InDJobOption = app.pdfExportPresets[myPreset-1];
myPDFFilePath = myOutFolderPathName+"/"+app.documents[0].name.split(".indd")[0].split(".INDD")[0]+".pdf";
app.documents[0].exportFile (ExportFormat.pdfType, myPDFFilePath, false, InDJobOption);
if(myWindow == true && myWin.myPDFExport){
var myPreset = app.pdfExportPresets.item;
myFile = File(+"PDF files: *.pdf");
}
thanks in advance,
simon
Copy link to clipboard
Copied
Simon,
Move app.documents[0].exportFile... inside if(myWindow == true && myWin.myPDFExport) statement.
Hope that helps.
--
Marijan (tomaxxi)
Copy link to clipboard
Copied
Hi Marijan,
Working great.
thanks
simon
Copy link to clipboard
Copied
This is how it could look like:
app.documents.length >= 1 ? doExport () : alert ( "No documents opened!" );
function doExport () {
var
myDoc = app.documents.item ( 0 ),
myPresets = app.pdfExportPresets.everyItem ().name,
myWin = new Window ( 'dialog', 'PDF Export Presets' ),
_u = undefined;
myPresets.unshift ( "- Select Preset - " ); myWin.orientation = 'row';
with ( myWin ) {
myWin.sText = add ( 'statictext', _u, '' );
var
pDrop = myWin.myPDFExport = add ( 'dropdownlist', _u, _u, { items : myPresets } ),
bOK = myWin.btnOK = add ( 'button', _u, 'OK' ),
bCanc = myWin.btnCancel = add ( 'button', _u, 'Cancel' );
pDrop.selection = 0;
};
bOK.onClick = function () { pDrop.selection == 0 ? alert ( "Please select valid PDF Preset!" ) : myWin.close ( 1 ); };
myWin.center ();
if ( myWin.show () == true ) {
var
myOutFolderPathName = "/Users/Desktop/Watched Folder/Out/", //Please change your path as per requirement
myPreset = app.pdfExportPresets [ pDrop.selection.index - 1 ],
myPDFFilePath = myOutFolderPathName + "/" + myDoc.name.replace ( ".indd", ".pdf" );
myDoc.exportFile ( ExportFormat.pdfType, myPDFFilePath, false, myPreset );
}
}
--
Marijan (tomaxxi)
Copy link to clipboard
Copied
Yes, this is better giving extra option alert, if selecting nothing
thanks Marijan
simon
Copy link to clipboard
Copied
Your program logic is wrong.
var myWindow = myWin.show(); // This shows the dialog and waits for your input
.. do the export ..
.. test if 'myWindow' = 'true' .. // test result of the show function
You want to test the result (the clicked button) before exporting.
(In addition, the result of 'show' is not a boolean value but rather the button index -- a number. With the Old Style dialogs, it returned a boolean 'true' or 'false' for "OK" or "Cancel". See Peter Kahrel's guide for examples of how to use the return value for ScriptUI.)
Message was edited by: [Jongware] Hi Marijan!

