Copy link to clipboard
Copied
Hi,
I have a handy script that exports my files to .png files. I need to change my script to export text files but I cannot find the appropriate ExportType for a .txt file. Can anyone help? See script below. Thank you very much in advance!!!
var j, sourceDoc, targetFile;
var destFolder = null;
// Get the destination to save the files
destFolder = Folder.selectDialog( 'Select the folder where you want to save the exported files.', '~' );
if (destFolder != null) {
for ( j = 0; j < app.documents.length; j++ ) {
sourceDoc = app.documents[ j ]; // returns the document object
targetFile = getNewName(sourceDoc, destFolder);
// set PNG export options
var opt = new ExportOptionsPNG24();
opt.antiAliasing = true;
opt.transparency = true;
// Export
sourceDoc.exportFile(targetFile, ExportType.PNG24, opt);
}
alert( 'Files are saved as PNG24 in ' + destFolder );
}
function getNewName(sourceDoc, destFolder) {
var docName = sourceDoc.name;
var ext = '.png'; // new extension for png file
var newName = "";
// if name has no dot (and hence no extension,
// just append the extension
if (docName.indexOf('.') < 0) {
newName = docName + ext;
} else {
var dot = docName.lastIndexOf('.');
newName += docName.substring(0, dot);
newName += ext;
}
// Create a file object to save the png
saveInFile = new File( destFolder + '/' + newName );
return saveInFile;
}
Copy link to clipboard
Copied
What exactly are you trying to achieve? It's make no sense to export an AI file as text. Usually there's very little text in an AI file.
Copy link to clipboard
Copied
Hi Larry,
I write large technical manuals with a large number of illustrations. The illustrations that have text in them I have to extract the text for translations. What I’m trying to do is automate the process by making a batch operation to do this for me which in return will automate my action of having to go export each one to a text file individually. I have attached two screenshots to help explain.
Copy link to clipboard
Copied
Larry is right there is no such thing as a 'save as' or 'export' to text file in Illustrator scripting… You would need to loop all the stories or text frames and use the standard write to file method…
Copy link to clipboard
Copied
here are the bare bone things you may need…
#target illustrator var textFile = File('~/Desktop/AI.txt'); var doc = app.activeDocument; var docText = ''; for (var i = 0; i < doc.textFrames.length; i++) { docText += doc.textFrames.contents + '\r'; } textFile.open('e'); textFile.write(docText); textFile.close();
I made no checks for an open doc or if it contained any text but you should get the general principle…
Copy link to clipboard
Copied
hello;
where did File class come from, please ... I do not see it within the illustrator_scripting_reference_javascript.pdf.
thanks.
Copy link to clipboard
Copied
The scripting PDF guides are specific to each app's DOM. For the classes etc. that are NOT there is a general guide JavaScript Tools Guide CS5.pdf for which ever instal you have that should be in the toolkit folder. There are classes for file system access as well as others. You can also see these in the toolkit if you use the object model viewer (OMV). That's comm+/ or in the help menu
Copy link to clipboard
Copied
I am getting off topic here ... sorry ... just curious though about the File class .... when I go to: https://developer.mozilla.org/en/JavaScript/Reference, it does not show the File class? I did find it in the OMV, but I prefer to rely on core documentations.
any thoughts?
again, sorry for taking the thread off topic!!!
Copy link to clipboard
Copied
Ah do NOT use that as your reference… Adobe uses it's own based on JavaScript 1.4 thats why its ExtendScript for these addional classes… You will have stuff there that just isn't available to you and stuff from the toolkit that just ain't there… See core classes here…
Copy link to clipboard
Copied
Muppet Mark wrote:
... See core classes here…
Or, if you abhor that abonimable interface as much as I do , see here: http://jongware.mit.edu/Js/index_1.html
It's the same information but with a much nicer presentation. (And lots more useful inter-subject links.)
Copy link to clipboard
Copied
CS6 ? :
Copy link to clipboard
Copied
So what you want to do is select all the text frames in a file, copy/paste them into a new file and export as a PDF. At least that's my proposed workflow.
Sorry I've been testing some other things and see mark has beaten me to it.
Works just fine.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now