0 Replies Latest reply on Jun 14, 2017 12:24 AM by weigajan

    Scripted DXF Export file differs from manually saved DXF File.

    weigajan

      Hi everybody,

       

      I made myself a script exporting the work area as a DXF File. Sadly the resulting file is not the same as when I do it manually.

      This wouldn't be a Problem, if the exported file could be opened in different applications (CAD Programs).

       

      Scripted Export Filesize: 14KB

      Manual Exported Filesize 52KB

       

      I tested all Autocad Versions, and all the other Scripting options, the result is the same. A small file which has nothing in it in CAD Programs (even though re-importing the file shows me the correct Paths in Illustrator).

       

      here the script ... if somebody wants to give it a go.

       

      var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pngExportOpts;
      
      // Select the source folder.
      sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PNG', '~' );
      
      // 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 PNG files.', '~' );
              
        destFolderpng = new Folder (files[0].parent+"/png");  
        if (!destFolderpng.exists) {  
          destFolderpng.create();
          } 
      
        destFolderdxf = new Folder (files[0].parent+"/dxf");  
        if (!destFolderdxf.exists) {  
          destFolderdxf.create();
          }
      
        destFoldersvg = new Folder (files[0].parent+"/svg");  
        if (!destFoldersvg.exists) {  
          destFoldersvg.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
          
        // Call function getNewName to get the name and file to save the png
        targetFile = getNewName(destFolderpng, '.png');
        pngExportOpts = getPNGOptions();
        sourceDoc.exportFile( targetFile, ExportType.PNG24, pngExportOpts );
      
        // export DXF
        targetFile = getNewName(destFolderdxf, '.dxf');
        dxfExportOpts = getDXFOptions();
        sourceDoc.exportFile( targetFile, ExportType.AUTOCAD, dxfExportOpts );
      
      
        // export SVG
        targetFile = getNewName(destFoldersvg, '.svg');
        svgExportOpts = getSVGOptions();
        sourceDoc.exportFile( targetFile, ExportType.SVG, svgExportOpts );
      
        sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
        }
        //alert( 'Done. ' + i + ' Files are saved as PNG and 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 = '.png'; // new extension for png file
          newName = "";
             
          for ( var i = 0 ; docName[i] != "." ; i++ )
          {
              newName += docName[i];
          }
          newName += ext; // full png name of the file
         
          // Create a file object to save the png
          saveInFile = new File( destFolder + '/' + newName );
      
          return saveInFile;
      }
      
      
      /*********************************************************
      
      getPNGOptions: Function to set the PNG saving options of the
      files using the PNGSaveOptions object.
      
      **********************************************************/
      
      function getPNGOptions()
      {
          // Create the PNGSaveOptions object to set the PNG options
          var pngExportOpts = new ExportOptionsPNG24();
          // Setting PNGExportOptions properties. Please see the JavaScript Reference
          // for a description of these properties.
          // Add more properties here if you like
          pngExportOpts.antiAliasing = true;
          pngExportOpts.artBoardClipping = false;    
          //pngExportOpts.matte = true;
          //pngExportOpts.matteColor = 0, 0, 0;
          pngExportOpts.saveAsHTML = false;
          pngExportOpts.transparency = false;
          pngExportOpts.horizontalScale = 1000.0; 
          pngExportOpts.verticalScale = 1000.0;
          return pngExportOpts;
      }
      
      
      function getDXFOptions()
      {
        var exportAutoCADOptions = new ExportOptionsAutoCAD();
        exportAutoCADOptions.exportFileFormat = AutoCADExportFileFormat.DXF;  // AutoCADExportFileFormat.DWG   DXF
        exportAutoCADOptions.exportOption = AutoCADExportOption.PreserveAppearance;  //PreserveAppearance MaximumEditability
        exportAutoCADOptions.version = AutoCADCompatibility.AutoCADRelease14;
        exportAutoCADOptions.exportSelectedArtOnly = false;
        exportAutoCADOptions.convertTextToOutlines = false;
        exportAutoCADOptions.unit = AutoCADUnit.Millimeters;
      }
      
      
      function getSVGOptions()
      {
        var exportsvgoptions = new ExportOptionsSVG();
        exportsvgoptions.coordinatePrecision = 3;
        exportsvgoptions.documentEncoding = SVGDocumentEncoding.UTF8;
        exportsvgoptions.DTD = SVGDTDVersion.SVG1_1;
        exportsvgoptions.embedRasterImages = false;
        exportsvgoptions.embedAllFonts = false;
        exportsvgoptions.fontSubsetting = SVGFontSubsetting.GLYPHSUSED;
      }
      

       

       

      Can Anybody confirm this?

      Or Help?