3

I would like to open a file dialog box seltect a CSV text file saved from Excel and import this into an array/variable/dataset in adobe illustrator using javascript. Have done some work with javascript but not a power user. Can't work out how to get the open dialog to appear.

Long term aim would be to use the data to plot a path which seems straighwforward enough, its the getting the info in bit I'm stuck on.

You do have to be able to select the file to import, this bit quite important.

Any help appreciated

Bob Haslett
  • 961
  • 1
  • 10
  • 31

1 Answers1

2

Just in case this one isn't solved yet: Look at my post #3 in http://forums.adobe.com/message/6084616

The CSV selecting part is

if (isOSX())
{
    var csvFile = File.openDialog('Select a CSV File', function (f) { return (f instanceof Folder) || f.name.match(/\.csv$/i);} );
} else
{
    var csvFile = File.openDialog('Select a CSV File','comma-separated-values(*.csv):*.csv;');
}
if (csvFile != null)
{
    fileArray = readInCSV(csvFile);
}

function readInCSV(fileObj)
{
     var fileArray = new Array();
     fileObj.open('r');
     fileObj.seek(0, 0);
     while(!fileObj.eof)
     {
          var thisLine = fileObj.readln();
          var csvArray = thisLine.split(',');
          fileArray.push(csvArray);
     }
     fileObj.close();
     return fileArray;
}

function isOSX()
{
    return $.os.match(/Macintosh/i);
}

When run, the variable fileArray will contain an array of array of values, split on the comma's. It parses basic CSV files only; tricks with quoted strings containing comma's are not allowed.

Jongware
  • 22,200
  • 8
  • 54
  • 100