How to fix unreadable or compiled exported DXF

时间:2019-01-07 13:20:18

标签: jsx autocad adobe-illustrator dxf

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.

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.

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 ?

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.

My code is partly coming from this thread : How can I run an Illustrator javascript on all files in a directory? (for selecting the whole directory)

And this thread : https://forums.adobe.com/thread/2345496 (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).

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 ?

Here is the 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 < 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 > 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 < 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;  
}  

0 个答案:

没有答案