Copy link to clipboard
Copied
Hello-
I am creating a script to help version my files. the intended goal is to export the active document to a child directory as a PNG. I have followed the CC 2014 scripting examples but the 'exportFile' method is returning undefined. Also in the Object viewer that method is not returned on search. I am trying to ascertain if that method has been deprecated in this latest release. I do not have experience with prior versions of Illustrator so I am not aware if how this functioned in past.
Has anyone had success with this method in CC 2014? Any Clarity lent would be appreciated.
Brian in NYC
var watchfolder = "/watchFolder";
exportPNGWithTimestamp (watchfolder);
function exportPNGWithTimestamp (watchfolder){
var date = new Date;
var month = date.getMonth() +1; //for zero index
var day = date.getDate();
var time = date.toLocaleTimeString();
var type = ExportType.PNG24;
var fileSpec= new File(watchfolder + "/" + app.activeDocument.name + "_" + month + "_" + day + "_" + time + ".png");
app.activeDocument.exportFile (fileSpec, type);
}
change your path to this and see if it works
var fileSpec= new File(Folder.desktop + "/" +doc.name + "_" );
if it does, the problem is in your path, look in the desktop for the png
Copy link to clipboard
Copied
sorry to not have too much time to look more into your problem, but to answer your question -- it does work fine in CC2014 and it has not been deprecated. I work mostly with VB.NET but I can tell you that regardless of the platform, you will need to include the object ExportOptionsPNG24 as a parameter -- something like this in JS:
...
var opts = new ExportOptionsPNG24();
app.activeDocument.exportFile ( fileSpec, type, opts );
...
Hope this helps somewhat.
Copy link to clipboard
Copied
Thank you for your Response ThinkingThings-
I thought that that was an optional argument. anyway I did add the Options array and unfortunately I have the same issue.
I put a breakpoint on line 30 and checked the fileSpec object. It is a [File] Object and the path is correct but then when I call 'exporFile' I get the same error. I am certainly a noob so I will continue to dig in.
//Represents the open file
var doc = app.activeDocument;
exportPNGWithTimestamp();
function exportPNGWithTimestamp (){
var grey= new RGBColor();
grey.red = 128;
grey.green = 128;
grey.blue = 128;
var date = new Date;
var month = date.getMonth() +1; //for zero index
var day = date.getDate();
var time = date.toLocaleTimeString();
var exportType = ExportType.PNG24;
var exportOptions = new ExportOptionsPNG24();
exportOptions.matte = true;
exportOptions.matteColor = grey;
var fileSpec= new File("watchFolder" + "/" +doc.name + "_" );
doc.exportFile (fileSpec, exportType, exportOptions);
}
Copy link to clipboard
Copied
If you are running it from the ESTK, make sure that the app you want is listed in the dropdown at the upper left and not the ESTK. Made this mistake with the same results.
Copy link to clipboard
Copied
change your path to this and see if it works
var fileSpec= new File(Folder.desktop + "/" +doc.name + "_" );
if it does, the problem is in your path, look in the desktop for the png
Copy link to clipboard
Copied
Carlos - Thanks!
I cleaned up the example and this function will export a PNG to a destination file, as long as it exists in the fs
//Represents the open file
var doc = app.activeDocument;
//set the Destination folder
var destFolder = "/watchFolder";
exportPNGTodestFolder(destFolder);
function exportPNGTodestFolder(dest){
var exportType = ExportType.PNG24;
//Return the path for the current file
var folder = new Folder(doc.fullName);
// create a random id
var tag = String(Math.random()) + "_";
// create a new file object for the exported file
var fileSpec= new File(folder.path + dest +"/" + tag + doc.name );
doc.exportFile (fileSpec, exportType);
}