Copy link to clipboard
Copied
hi there!
I'm currently writing a script that exports all the open documents to a JPEG.
this works except for one little thingy:
instead of exporting all the documents, it exports only the active one, with all the other document names...
so for example:
3 files opened, 3 files exported with a different, correct filename, BUT every jpeg shows the active file.
I don't know what I'm doing wrong, so if someone could jump in = AWESOME!
TY!
M.
this is my code:
try {
if (app.documents.length > 0 ) {
// Get the folder to save the files into
var destFolder = null;
destFolder = Folder.selectDialog( 'Select folder for JPG files.', '~' );
if (destFolder != null) {
var options, i;
// Get the Flash export options to be used.
var options = new ExportOptionsJPEG();
// You can tune these by changing the code in the getOptions() function.
for ( i = app.documents.length-1; i >=0 ; i-- ) {
// Get the file to export the document as swf intos
var targetFile = new File( destFolder + '/' + app.documents.name +".jpg");
// Export to flash
app.documents.exportFile(targetFile, ExportType.JPEG, options);
app.documents.close();
}
alert( 'Documents exported as JPG' );
}
}
else{
throw new Error('There are no document open!');
}
}
catch(e) {
alert( e.message, "Script Alert", true);
}
Changing your 'for' loop to a 'while' loop and working with 'activeDocument' rather than documents works fine for me…
Like so…
try {
if (app.documents.length > 0 ) {
// Get the folder to save the files into
var destFolder = null;
destFolder = Folder.selectDialog( 'Select folder for JPG files.', '~' );
if (destFolder != null) {
var options, i;
// Get the Flash export options to be used.
var options = new ExportOptionsJPEG();
...
Copy link to clipboard
Copied
Changing your 'for' loop to a 'while' loop and working with 'activeDocument' rather than documents works fine for me…
Like so…
try {
if (app.documents.length > 0 ) {
// Get the folder to save the files into
var destFolder = null;
destFolder = Folder.selectDialog( 'Select folder for JPG files.', '~' );
if (destFolder != null) {
var options, i;
// Get the Flash export options to be used.
var options = new ExportOptionsJPEG();
// You can tune these by changing the code in the getOptions() function.
while (app.documents.length > 0) {
// Get the file to export the document as swf intos
var targetFile = new File( destFolder + '/' + app.activeDocument.name +".jpg");
// Export to flash
app.activeDocument.exportFile(targetFile, ExportType.JPEG, options);
app.activeDocument.close();
}
alert( 'Documents exported as JPG' );
}
}
else{
throw new Error('There are no document open!');
}
}
catch(e) {
alert( e.message, "Script Alert", true);
}
Copy link to clipboard
Copied
Muppet Mark, you are a life saver! works like a charm!
Thanks!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now