Skip to main content
Participant
March 16, 2018
Answered

exporting selected objects to dxf

  • March 16, 2018
  • 1 reply
  • 2672 views

I have tried everything to write a script and I cant.  I am not experienced but I copied and pasted with no luck.  can anyone help.  all I need is to quickly export selected objects with one click to a temp folder

here is what I have

try {
if (app.documents.length > 0 ) {


  var destFolder = null;
  destFolder = Folder.selectDialog( 'Select folder for dxf files.', '~' );
  
  if (destFolder != null) {
   var options, i, sourceDoc, targetFile; 

   options = this.getOptions();
       
      for ( i = 0; i < app.documents.length; i++ ) {
       sourceDoc = app.documents; // returns the document object
        
 
    targetFile = this.getTargetFile(sourceDoc.name, '.dxf', destFolder);
  
    sourceDoc.exportFile(targetFile, ExportType.dxf, options);
   }
   alert( 'Documents exported as dxf' );
  }
}
else{
  throw new Error('There are no document open!');
}
}
catch(e) {
alert( e.message, "Script Alert", true);
}

var exportOptions = new ExportOptionsAUTOCAD(); {
var type = ExportType.DXF; 
var file = new File(folder.fsName+"/"+layer.name+".DXF");
                    document.exportFile(file, ExportType.DXF, options);
   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; 
        app.activeDocument.exportFile( fileSpec, type, exportOptions ); 
     return options;
}

/** Returns the file to save or export into.
@9397041 docName the name of the document to be saved or exported
@9397041 ext the extension the file extension to be applied
@9397041 destFolder the output folder
@Return File object
*/
function getTargetFile(docName, ext, destFolder) {
var newName = "";


if (docName.indexOf('.') < 0) {
  newName = docName + ext;
} else {
  var dot = docName.lastIndexOf('.');
  newName += docName.substring(0, dot);

This topic has been closed for replies.
Correct answer renél80416020

Bonjour,

Gaz factory

Un peu d'ordre ne fait pas de mal !

// JavaScript Document for Illustrator

// elleere Sat, 17 March 2018 20:39:43 GMT

var doc = app.activeDocument;

if ( app.documents.length > 0 ) {

    var destFolder = null;

        destFolder = Folder.selectDialog( 'Sélectionner le dossier des fichiers DXF.', '~' );

    if (destFolder != null) {

      var options = getOptions();

      var type = ExportType.AUTOCAD;

      var fileSpec = new File(destFolder+"/"+doc.name+".dxf"); //  "~/essai.dxf"

      doc.exportFile( fileSpec, type, options );

    }

}

//--------

function getOptions() {

  var exportOptions = new ExportOptionsAutoCAD();

      exportOptions.exportFileFormat = AutoCADExportFileFormat.DXF;//DWG  DXF

      exportOptions.exportOption = AutoCADExportOption.PreserveAppearance;

      exportOptions.version = AutoCADCompatibility.AutoCADRelease14;

      exportOptions.exportSelectedArtOnly = true; //export selected objects true

      exportOptions.convertTextToOutlines = false;

      exportOptions.generateThumbnails = true

      exportOptions.unit = AutoCADUnit.Millimeters;

    return exportOptions;

}

de elleere

1 reply

renél80416020
renél80416020Correct answer
Inspiring
March 17, 2018

Bonjour,

Gaz factory

Un peu d'ordre ne fait pas de mal !

// JavaScript Document for Illustrator

// elleere Sat, 17 March 2018 20:39:43 GMT

var doc = app.activeDocument;

if ( app.documents.length > 0 ) {

    var destFolder = null;

        destFolder = Folder.selectDialog( 'Sélectionner le dossier des fichiers DXF.', '~' );

    if (destFolder != null) {

      var options = getOptions();

      var type = ExportType.AUTOCAD;

      var fileSpec = new File(destFolder+"/"+doc.name+".dxf"); //  "~/essai.dxf"

      doc.exportFile( fileSpec, type, options );

    }

}

//--------

function getOptions() {

  var exportOptions = new ExportOptionsAutoCAD();

      exportOptions.exportFileFormat = AutoCADExportFileFormat.DXF;//DWG  DXF

      exportOptions.exportOption = AutoCADExportOption.PreserveAppearance;

      exportOptions.version = AutoCADCompatibility.AutoCADRelease14;

      exportOptions.exportSelectedArtOnly = true; //export selected objects true

      exportOptions.convertTextToOutlines = false;

      exportOptions.generateThumbnails = true

      exportOptions.unit = AutoCADUnit.Millimeters;

    return exportOptions;

}

de elleere

Participating Frequently
September 6, 2023

operation not supported on this object

 

 

Sergey Osokin
Inspiring
September 6, 2023

If possible, please send the full script code for the community to review. At first glance, there are no problems in these lines and the export will work.