title: How to fix unreadable or compiled exported DXF
body: <p>I am an archaeologist trying to make a georeferenced 3D visualisation of the drawings we did on an excavation. The hundreds of drawings have been done with Illustrator CS6 and are then read by AutoCad Map 2018 and Covadis 16.0b. The drawings are in .ai, and I use a .jsx script to automatically export them to .dxf (saving days of work, there are hundreds of files and possibly thousands in the future if this works). 
  My colleague, who does the final work with AutoCad, can read the files perfectly when I export them manually (in 2004/2005/2006 AutoCad format). However, he cannot do it when I export them automatically, but I can read them with Illustrator.</p>
  
  <p>I am not a developer, and there are no dev at my workplace. I only know how to slightly modify a code, or understand which part in a code relate to which action. </p>
  
  <p>I think the problem lies in the exported version (line 107): it is AutoCad 2018, and my colleague already had issues with it, that’s why they always ask for dxf in 2004/2005/2006 AutoCad version. I tried to (nearly randomly) find the correct syntax for such a version, but I couldn’t. And for security issues, we cannot update nor install anything on our computers. Does anyone know the syntax ?</p>
  
  <p>My other less optimistic guess is that the script as a whole is disfunctionnal : the dxf I export with it appear to be compiled, whether the ones I export manually are not.</p>
  
  <p>My code is partly coming from this thread : <a href="https://stackoverflow.com/questions/34920139/how-can-i-run-an-illustrator-javascript-on-all-files-in-a-directory">How can I run an Illustrator javascript on all files in a directory?</a> (for selecting the whole directory)</p>
  
  <p>And this thread : <a href="https://forums.adobe.com/thread/2345496" rel="nofollow noreferrer">https://forums.adobe.com/thread/2345496</a> (although I modified it a bit because I only needed dxf format, but since this is an unresolved thread, I’m afraid to be mistaken about the real problem).</p>
  
  <p>Extra question : The drawings are done with a scale of 1-20, and he needs them at a scale of 1-1. I think the line for the scale is 110, does anyone know how to export at such a scale ?</p>
  
  <p>Here is the code :  </p>
  
  <pre><code> //Beginning of the selecter script
  // Select several files at once
  
  var dir = Folder.selectDialog("Where?");
  var files = dir.getFiles("*.eps");
  
  for(var f = 0; f &lt; files.length; f++){
      var doc = app.open(files[f]);
      //Your processing
      doc.close(SaveOptions.SAVECHANGES);
  }
  
  
  var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, dxfExportOpts;  
  
  // Beginning of the exporter script
  // Select the source folder.  
  sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to DXF', '~' );  
  
  // If a valid folder is selected  
  if ( sourceFolder != null )  
  {  
      files = new Array();  
      //fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', '*.ai' );  
      fileType = "*.ai"  
      // Get all files matching the pattern  
      files = sourceFolder.getFiles( fileType );  
  
      if ( files.length &gt; 0 )  
      {  
          // Get the destination to save the files  
          // destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted dxf files.', '~' );  
  
    destFolderdxf = new Folder (files[0].parent+"/dxf");    
    if (!destFolderdxf.exists) {    
      destFolderdxf.create();  
      }  
  
    if(confirm( files.length + ' found.\nFiles will be saved in respective extension folders.\nPlease wait even if you get a spinning wheel.\n\nProceed with saving files?'))  
    {  
    for ( i = 0; i &lt; files.length; i++ )  
    {  
    sourceDoc = app.open(files[i]); // returns the document object  
  
    // export DXF  
    targetFile = getNewName(destFolderdxf, '.dxf');  
    dxfExportOpts = getDXFOptions();  
    sourceDoc.exportFile( targetFile, ExportType.AUTOCAD, dxfExportOpts );  
  
  
    sourceDoc.close(SaveOptions.DONOTSAVECHANGES);  
    }  
    //alert( 'Done. ' + i + ' Files are saved as DXF.');  
    }  
    else  
    {  
    alert( 'No matching files found' );  
    }  
    }  
    else  
    {  
    // Do nothing!  
     }    
  }  
  
  
  /********************************************************* 
  
  getNewName: Function to get the new file name. The primary 
  name is the same as the source file. 
  
  **********************************************************/  
  
  function getNewName(destFolder, ext)  
  {  
      var ext, docName, newName, saveInFile, docName;  
      docName = sourceDoc.name;  
      //ext = '.dxf'; // new extension for dxf file  
      newName = "";  
  
      for ( var i = 0 ; docName[i] != "." ; i++ )  
      {  
          newName += docName[i];  
      }  
      newName += ext; // full dxf name of the file  
  
      // Create a file object to save the dxf  
      saveInFile = new File( destFolder + '/' + newName );  
  
      return saveInFile;  
  }  
  
  
  /********************************************************* 
  
  getDXFOptions: Function to set the DXF saving options of the 
  files using the dxfSaveOptions object. 
  
  **********************************************************/  
  
  
  function getDXFOptions()  
  {  
    var exportAutoCADOptions = new ExportOptionsAutoCAD();  
    exportAutoCADOptions.exportFileFormat = AutoCADExportFileFormat.DXF;  // AutoCADExportFileFormat.DWG   DXF  
    exportAutoCADOptions.exportOption = AutoCADExportOption.MaximumEditability;  //PreserveAppearance MaximumEditability  
    exportAutoCADOptions.version = AutoCADCompatibility.AutoCADRelease18;  
    exportAutoCADOptions.exportSelectedArtOnly = false;  
    exportAutoCADOptions.convertTextToOutlines = false;  
    exportAutoCADOptions.unit = AutoCADUnit.Millimeters;  
  }  
  </code></pre>