Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help, Need to change ExportType

Explorer ,
Apr 29, 2011 Apr 29, 2011

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;

}

TOPICS
Scripting
2.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Apr 29, 2011 Apr 29, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 29, 2011 Apr 29, 2011

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.

Window Capture.pngWindow Capture1.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 29, 2011 Apr 29, 2011

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 29, 2011 Apr 29, 2011

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 04, 2012 Jun 04, 2012

hello;

where did File class come from, please ... I do not see it within the illustrator_scripting_reference_javascript.pdf.

thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 04, 2012 Jun 04, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 04, 2012 Jun 04, 2012

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!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 04, 2012 Jun 04, 2012

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…

Screen shot 2012-06-04 at 10.56.23.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 04, 2012 Jun 04, 2012

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.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 04, 2012 Jun 04, 2012
LATEST

CS6 ? :

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 29, 2011 Apr 29, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines